Skip to content

Commit b8da844

Browse files
authored
Merge pull request #254 from python/bugfix/253-multiplexed-path-compound-path-non-existent-parent
Restore lenience in MultiplexedPath.joinpath for missing directories
2 parents 5a14cdc + 41d8e32 commit b8da844

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

CHANGES.rst

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
v5.8.1
2+
======
3+
4+
* #253: In ``MultiplexedPath``, restore expectation that
5+
a compound path with a non-existent directory does not
6+
raise an exception.
7+
18
v5.8.0
29
======
310

importlib_resources/readers.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,10 @@ def is_file(self):
8585
def joinpath(self, *descendants):
8686
try:
8787
return super().joinpath(*descendants)
88-
except abc.TraversalError as exc:
89-
# One of the paths didn't resolve.
90-
msg, target, names = exc.args
91-
if names: # pragma: nocover
92-
raise
93-
# It was the last; construct result with the first path.
94-
return self._paths[0].joinpath(target)
88+
except abc.TraversalError:
89+
# One of the paths did not resolve (a directory does not exist).
90+
# Just return something that will not exist.
91+
return self._paths[0].joinpath(*descendants)
9592

9693
def open(self, *args, **kwargs):
9794
raise FileNotFoundError(f'{self} is not a file')

importlib_resources/tests/test_reader.py

+4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ def test_join_path(self):
7777
)
7878
self.assertEqual(path.joinpath(), path)
7979

80+
def test_join_path_compound(self):
81+
path = MultiplexedPath(self.folder)
82+
assert not path.joinpath('imaginary/foo.py').exists()
83+
8084
def test_repr(self):
8185
self.assertEqual(
8286
repr(MultiplexedPath(self.folder)),

0 commit comments

Comments
 (0)