Skip to content

Commit c02bc7e

Browse files
committed
Update MultiplexedPath to expect Traversable and add a compatibility shim with deprecation warning.
1 parent 1d91410 commit c02bc7e

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

importlib_resources/_compat.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import sys
66
import pathlib
7+
import warnings
78
from contextlib import suppress
89
from typing import Union
910

@@ -107,3 +108,19 @@ def wrap_spec(package):
107108
else:
108109
# PathLike is only subscriptable at runtime in 3.9+
109110
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from . import abc
77

88
from ._itertools import only
9-
from ._compat import ZipPath
9+
from ._compat import ZipPath, ensure_traversable
1010

1111

1212
def remove_duplicates(items):
@@ -62,7 +62,7 @@ class MultiplexedPath(abc.Traversable):
6262
"""
6363

6464
def __init__(self, *paths):
65-
self._paths = list(map(pathlib.Path, remove_duplicates(paths)))
65+
self._paths = list(map(ensure_traversable, remove_duplicates(paths)))
6666
if not self._paths:
6767
message = 'MultiplexedPath must contain at least one path'
6868
raise FileNotFoundError(message)

0 commit comments

Comments
 (0)