Skip to content

Commit

Permalink
Move '_ensure_traversable' to the readers module, as it's needed down…
Browse files Browse the repository at this point in the history
…stream.
  • Loading branch information
jaraco committed Feb 25, 2024
1 parent 56915b8 commit 3cf884a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
16 changes: 0 additions & 16 deletions importlib_resources/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,3 @@ def wrap_spec(package):
else:
# PathLike is only subscriptable at runtime in 3.9+
StrPath = Union[str, "os.PathLike[str]"]


def ensure_traversable(path):
"""
Convert deprecated string arguments to traversables (pathlib.Path).
"""
if not isinstance(path, str):
return path

warnings.warn(
"String arguments are deprecated. Pass a Traversable instead.",
DeprecationWarning,
stacklevel=3,
)

return pathlib.Path(path)
23 changes: 21 additions & 2 deletions importlib_resources/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import pathlib
import operator
import re
import warnings

from . import abc

from ._itertools import only
from ._compat import ZipPath, ensure_traversable
from ._compat import ZipPath


def remove_duplicates(items):
Expand Down Expand Up @@ -64,7 +65,7 @@ class MultiplexedPath(abc.Traversable):
"""

def __init__(self, *paths):
self._paths = list(map(ensure_traversable, remove_duplicates(paths)))
self._paths = list(map(_ensure_traversable, remove_duplicates(paths)))
if not self._paths:
message = 'MultiplexedPath must contain at least one path'
raise FileNotFoundError(message)
Expand Down Expand Up @@ -170,3 +171,21 @@ def resource_path(self, resource):

def files(self):
return self.path


def _ensure_traversable(path):
"""
Convert deprecated string arguments to traversables (pathlib.Path).
Remove with Python 3.15.
"""
if not isinstance(path, str):
return path

warnings.warn(
"String arguments are deprecated. Pass a Traversable instead.",
DeprecationWarning,
stacklevel=3,
)

return pathlib.Path(path)

0 comments on commit 3cf884a

Please sign in to comment.