Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
v5.8.1
======

* #253: In ``MultiplexedPath``, restore expectation that
a compound path with a non-existent directory does not
raise an exception.

v5.8.0
======

Expand Down
11 changes: 4 additions & 7 deletions importlib_resources/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,10 @@ def is_file(self):
def joinpath(self, *descendants):
try:
return super().joinpath(*descendants)
except abc.TraversalError as exc:
# One of the paths didn't resolve.
msg, target, names = exc.args
if names: # pragma: nocover
raise
# It was the last; construct result with the first path.
return self._paths[0].joinpath(target)
except abc.TraversalError:
# One of the paths did not resolve (a directory does not exist).
# Just return something that will not exist.
return self._paths[0].joinpath(*descendants)

def open(self, *args, **kwargs):
raise FileNotFoundError(f'{self} is not a file')
Expand Down
4 changes: 4 additions & 0 deletions importlib_resources/tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ def test_join_path(self):
)
self.assertEqual(path.joinpath(), path)

def test_join_path_compound(self):
path = MultiplexedPath(self.folder)
assert not path.joinpath('imaginary/foo.py').exists()

def test_repr(self):
self.assertEqual(
repr(MultiplexedPath(self.folder)),
Expand Down