[issue39980] importlib.resources.path() may return incorrect path when using custom loader
Krzysztof Rusek added the comment: I can confirm that this problem doesn't occur when using recent version of importlib_resources (checked importlib_resources==1.3.1). -- ___ Python tracker <https://bugs.python.org/issue39980> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39980] importlib.resources.path() may return incorrect path when using custom loader
Krzysztof Rusek added the comment: Maybe importlib.resources.path() should skip checking file existence when ResourceReader.resource_path() raises FileNotFoundError? Current logic: @contextmanager def path(package: Package, resource: Resource) -> Iterator[Path]: resource = _normalize_path(resource) package = _get_package(package) reader = _get_resource_reader(package) if reader is not None: try: yield Path(reader.resource_path(resource)) return except FileNotFoundError: pass else: _check_location(package) # Fall-through for both the lack of resource_path() *and* if # resource_path() raises FileNotFoundError. package_directory = Path(package.__spec__.origin).parent file_path = package_directory / resource if file_path.exists(): yield file_path else: -- ___ Python tracker <https://bugs.python.org/issue39980> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39980] importlib.resources.path() may return incorrect path when using custom loader
New submission from Krzysztof Rusek : importlib.resources.path() function may return a path to a file with different contents than expected. This may happen when using a custom loader implementation that uses fake filenames (like ''). I'm attaching a reproduction test (resources.py). -- components: Library (Lib) files: resources.py messages: 364352 nosy: Krzysztof Rusek priority: normal severity: normal status: open title: importlib.resources.path() may return incorrect path when using custom loader versions: Python 3.7, Python 3.8, Python 3.9 Added file: https://bugs.python.org/file48978/resources.py ___ Python tracker <https://bugs.python.org/issue39980> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com