[issue39980] importlib.resources.path() may return incorrect path when using custom loader
Krzysztof Rusek
report at bugs.python.org
Mon Mar 16 15:02:50 EDT 2020
Krzysztof Rusek <savix5 at gmail.com> 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:
<create temporary file>
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39980>
_______________________________________
More information about the Python-bugs-list
mailing list