Skip to content

Commit be65d3d

Browse files
committed
Move compatibility and future behaviors into separate packages.
1 parent 3cf884a commit be65d3d

File tree

8 files changed

+26
-33
lines changed

8 files changed

+26
-33
lines changed

importlib_resources/_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from typing import Union, Optional, cast
1313
from .abc import ResourceReader, Traversable
1414

15-
from ._compat import wrap_spec
15+
from .future.adapters import wrap_spec
1616

1717
Package = Union[types.ModuleType, str]
1818
Anchor = Package

importlib_resources/abc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
import itertools
44
import pathlib
55
from typing import Any, BinaryIO, Iterable, Iterator, NoReturn, Text, Optional
6+
from typing import runtime_checkable, Protocol
67

7-
from ._compat import runtime_checkable, Protocol, StrPath
8+
from .compat.py38 import StrPath
89

910

1011
__all__ = ["ResourceReader", "Traversable", "TraversableResources"]

importlib_resources/compat/__init__.py

Whitespace-only changes.

importlib_resources/compat/py38.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import os
2+
import sys
3+
4+
from typing import Union
5+
6+
7+
if sys.version_info >= (3, 9):
8+
StrPath = Union[str, os.PathLike[str]]
9+
else:
10+
# PathLike is only subscriptable at runtime in 3.9+
11+
StrPath = Union[str, "os.PathLike[str]"]

importlib_resources/compat/py39.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import sys
2+
3+
4+
__all__ = ['ZipPath']
5+
6+
7+
if sys.version_info >= (3, 10):
8+
from zipfile import Path as ZipPath # type: ignore
9+
else:
10+
from zipp import Path as ZipPath # type: ignore

importlib_resources/future/__init__.py

Whitespace-only changes.

importlib_resources/_compat.py renamed to importlib_resources/future/adapters.py

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,7 @@
88
from contextlib import suppress
99
from typing import Union
1010

11-
12-
if sys.version_info >= (3, 10):
13-
from zipfile import Path as ZipPath # type: ignore
14-
else:
15-
from zipp import Path as ZipPath # type: ignore
16-
17-
18-
try:
19-
from typing import runtime_checkable # type: ignore
20-
except ImportError:
21-
22-
def runtime_checkable(cls): # type: ignore
23-
return cls
24-
25-
26-
try:
27-
from typing import Protocol # type: ignore
28-
except ImportError:
29-
Protocol = abc.ABC # type: ignore
11+
from .. import readers, _adapters
3012

3113

3214
class TraversableResourcesLoader:
@@ -46,8 +28,6 @@ def path(self):
4628
return self.spec.origin
4729

4830
def get_resource_reader(self, name):
49-
from . import readers, _adapters
50-
5131
def _zip_reader(spec):
5232
with suppress(AttributeError):
5333
return readers.ZipReader(spec.loader, spec.name)
@@ -98,13 +78,4 @@ def wrap_spec(package):
9878
Supersedes _adapters.wrap_spec to use TraversableResourcesLoader
9979
from above for older Python compatibility (<3.10).
10080
"""
101-
from . import _adapters
102-
10381
return _adapters.SpecLoaderAdapter(package.__spec__, TraversableResourcesLoader)
104-
105-
106-
if sys.version_info >= (3, 9):
107-
StrPath = Union[str, os.PathLike[str]]
108-
else:
109-
# PathLike is only subscriptable at runtime in 3.9+
110-
StrPath = Union[str, "os.PathLike[str]"]

importlib_resources/readers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from . import abc
1010

1111
from ._itertools import only
12-
from ._compat import ZipPath
12+
from .compat.py39 import ZipPath
1313

1414

1515
def remove_duplicates(items):

0 commit comments

Comments
 (0)