summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/resources.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2018-01-15 23:07:11 (GMT)
committerGitHub <noreply@github.com>2018-01-15 23:07:11 (GMT)
commit5ec0feeeecc1617987ec6cdc6d62b916e718a5cf (patch)
tree158c8a278acd9a7d2de71553c22199aa9b5b6ec6 /Lib/importlib/resources.py
parent21102f0dc20cc347677191817c1b66e20ef7bf21 (diff)
downloadcpython-5ec0feeeecc1617987ec6cdc6d62b916e718a5cf.zip
cpython-5ec0feeeecc1617987ec6cdc6d62b916e718a5cf.tar.gz
cpython-5ec0feeeecc1617987ec6cdc6d62b916e718a5cf.tar.bz2
Implement the get_resource_reader() API for file system imports (#5168)
Diffstat (limited to 'Lib/importlib/resources.py')
-rw-r--r--Lib/importlib/resources.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/importlib/resources.py b/Lib/importlib/resources.py
index 8511f24..20888df 100644
--- a/Lib/importlib/resources.py
+++ b/Lib/importlib/resources.py
@@ -59,8 +59,10 @@ def _get_resource_reader(
# hook wants to create a weak reference to the object, but
# zipimport.zipimporter does not support weak references, resulting in a
# TypeError. That seems terrible.
- if hasattr(package.__spec__.loader, 'open_resource'):
- return cast(resources_abc.ResourceReader, package.__spec__.loader)
+ spec = package.__spec__
+ if hasattr(spec.loader, 'get_resource_reader'):
+ return cast(resources_abc.ResourceReader,
+ spec.loader.get_resource_reader(spec.name))
return None