diff --git a/CHANGES.rst b/CHANGES.rst index 5321b177..570fe86f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 ====== diff --git a/importlib_resources/readers.py b/importlib_resources/readers.py index 19450f46..ab34db74 100644 --- a/importlib_resources/readers.py +++ b/importlib_resources/readers.py @@ -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') diff --git a/importlib_resources/tests/test_reader.py b/importlib_resources/tests/test_reader.py index 37550cad..1c8ebeeb 100644 --- a/importlib_resources/tests/test_reader.py +++ b/importlib_resources/tests/test_reader.py @@ -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)),