Skip to content

Commit 2331da9

Browse files
committed
Only replace readers if they're actually stdlib loaders/readers and not simply seemingly compatible instances.
1 parent 56915b8 commit 2331da9

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

importlib_resources/_compat.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,21 @@ def _file_reader(spec):
7272
if path.exists():
7373
return readers.FileReader(self)
7474

75+
def _is_stdlib_reader(spec):
76+
return spec.loader.__class__.__module__.startswith('_frozen_importlib')
77+
7578
return (
76-
# local ZipReader if a zip module
77-
_zip_reader(self.spec)
78-
or
79-
# local NamespaceReader if a namespace module
80-
_namespace_reader(self.spec)
81-
or
82-
# local FileReader
83-
_file_reader(self.spec)
79+
_is_stdlib_reader(self.spec)
80+
and (
81+
# local ZipReader if a zip module
82+
_zip_reader(self.spec)
83+
or
84+
# local NamespaceReader if a namespace module
85+
_namespace_reader(self.spec)
86+
or
87+
# local FileReader
88+
_file_reader(self.spec)
89+
)
8490
or
8591
# native reader if it supplies 'files'
8692
_native_reader(self.spec)

0 commit comments

Comments
 (0)