Skip to content

Commit 3cf884a

Browse files
committed
Move '_ensure_traversable' to the readers module, as it's needed downstream.
1 parent 56915b8 commit 3cf884a

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

importlib_resources/_compat.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,3 @@ def wrap_spec(package):
108108
else:
109109
# PathLike is only subscriptable at runtime in 3.9+
110110
StrPath = Union[str, "os.PathLike[str]"]
111-
112-
113-
def ensure_traversable(path):
114-
"""
115-
Convert deprecated string arguments to traversables (pathlib.Path).
116-
"""
117-
if not isinstance(path, str):
118-
return path
119-
120-
warnings.warn(
121-
"String arguments are deprecated. Pass a Traversable instead.",
122-
DeprecationWarning,
123-
stacklevel=3,
124-
)
125-
126-
return pathlib.Path(path)

importlib_resources/readers.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
import pathlib
55
import operator
66
import re
7+
import warnings
78

89
from . import abc
910

1011
from ._itertools import only
11-
from ._compat import ZipPath, ensure_traversable
12+
from ._compat import ZipPath
1213

1314

1415
def remove_duplicates(items):
@@ -64,7 +65,7 @@ class MultiplexedPath(abc.Traversable):
6465
"""
6566

6667
def __init__(self, *paths):
67-
self._paths = list(map(ensure_traversable, remove_duplicates(paths)))
68+
self._paths = list(map(_ensure_traversable, remove_duplicates(paths)))
6869
if not self._paths:
6970
message = 'MultiplexedPath must contain at least one path'
7071
raise FileNotFoundError(message)
@@ -170,3 +171,21 @@ def resource_path(self, resource):
170171

171172
def files(self):
172173
return self.path
174+
175+
176+
def _ensure_traversable(path):
177+
"""
178+
Convert deprecated string arguments to traversables (pathlib.Path).
179+
180+
Remove with Python 3.15.
181+
"""
182+
if not isinstance(path, str):
183+
return path
184+
185+
warnings.warn(
186+
"String arguments are deprecated. Pass a Traversable instead.",
187+
DeprecationWarning,
188+
stacklevel=3,
189+
)
190+
191+
return pathlib.Path(path)

0 commit comments

Comments
 (0)