diff --git a/importlib_resources/_compat.py b/importlib_resources/_compat.py index d7e9f0d..519ccfa 100644 --- a/importlib_resources/_compat.py +++ b/importlib_resources/_compat.py @@ -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) diff --git a/importlib_resources/readers.py b/importlib_resources/readers.py index 1e2d1ba..ef2d21a 100644 --- a/importlib_resources/readers.py +++ b/importlib_resources/readers.py @@ -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): @@ -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) @@ -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)