summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/importlib/_bootstrap.py6
-rw-r--r--Lib/test/test_imp.py11
2 files changed, 15 insertions, 2 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index 857583a..70b706a 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -786,6 +786,8 @@ class FrozenImporter:
"""
+ _ORIGIN = "frozen"
+
@staticmethod
def module_repr(m):
"""Return repr for the module.
@@ -793,12 +795,12 @@ class FrozenImporter:
The method is deprecated. The import machinery does the job itself.
"""
- return '<module {!r} (frozen)>'.format(m.__name__)
+ return '<module {!r} ({})>'.format(m.__name__, FrozenImporter._ORIGIN)
@classmethod
def find_spec(cls, fullname, path=None, target=None):
if _imp.is_frozen(fullname):
- return spec_from_loader(fullname, cls, origin='frozen')
+ return spec_from_loader(fullname, cls, origin=cls._ORIGIN)
else:
return None
diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py
index bb0144b..fe394dc 100644
--- a/Lib/test/test_imp.py
+++ b/Lib/test/test_imp.py
@@ -332,6 +332,17 @@ class ImportTests(unittest.TestCase):
with self.assertRaises(TypeError):
create_dynamic(BadSpec())
+ def test_issue_35321(self):
+ # Both _frozen_importlib and _frozen_importlib_external
+ # should have a spec origin of "frozen" and
+ # no need to clean up imports in this case.
+
+ import _frozen_importlib_external
+ self.assertEqual(_frozen_importlib_external.__spec__.origin, "frozen")
+
+ import _frozen_importlib
+ self.assertEqual(_frozen_importlib.__spec__.origin, "frozen")
+
def test_source_hash(self):
self.assertEqual(_imp.source_hash(42, b'hi'), b'\xc6\xe7Z\r\x03:}\xab')
self.assertEqual(_imp.source_hash(43, b'hi'), b'\x85\x9765\xf8\x9a\x8b9')