Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Lib/importlib/_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,19 +786,21 @@ class FrozenImporter:

"""

_ORIGIN = "frozen"

@staticmethod
def module_repr(m):
"""Return repr for the module.

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

Expand Down
11 changes: 11 additions & 0 deletions Lib/test/test_imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,17 @@ class BadSpec:
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')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Set ``__spec__.origin`` of ``_frozen_importlib`` to frozen so that it matches the behavior of ``_frozen_importlib_external``. Patch by Nina Zakharenko.
Loading