gh-123987: Fix NotADirectoryError in NamespaceReader when sentinel present (#124018)

This commit is contained in:
Jason R. Coombs 2025-01-26 11:23:54 -05:00 committed by GitHub
parent fccbfc40b5
commit b543b32eff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 93 additions and 18 deletions

View file

@ -66,10 +66,10 @@ def get_resource_reader(package: types.ModuleType) -> Optional[ResourceReader]:
# zipimport.zipimporter does not support weak references, resulting in a
# TypeError. That seems terrible.
spec = package.__spec__
reader = getattr(spec.loader, 'get_resource_reader', None) # type: ignore
reader = getattr(spec.loader, 'get_resource_reader', None) # type: ignore[union-attr]
if reader is None:
return None
return reader(spec.name) # type: ignore
return reader(spec.name) # type: ignore[union-attr]
@functools.singledispatch