-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-45324: Capture data in FrozenImporter.find_spec() to use in exec_module(). #28633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
97bdaa2
e2e676d
6333212
8cd239b
7724019
0dd3870
1a0ad16
fdf7689
385d412
e0fe501
7221e0e
5f68ee8
7b85a63
cdbc611
c6e70cc
f86dcd5
d1b1868
4e105a9
5d6af1e
017c932
1a833ed
5363708
07c947f
cddf089
ca0500f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -826,10 +826,15 @@ def module_repr(m): | |
|
||
@classmethod | ||
def find_spec(cls, fullname, path=None, target=None): | ||
if _imp.is_frozen(fullname): | ||
return spec_from_loader(fullname, cls, origin=cls._ORIGIN) | ||
else: | ||
info = _call_with_frames_removed(_imp.find_frozen, fullname) | ||
if info is None: | ||
return None | ||
data, ispkg = info | ||
spec = spec_from_loader(fullname, cls, | ||
origin=cls._ORIGIN, | ||
is_package=ispkg) | ||
spec.loader_state = data | ||
return spec | ||
|
||
@classmethod | ||
def find_module(cls, fullname, path=None): | ||
|
@@ -849,11 +854,22 @@ def create_module(spec): | |
|
||
@staticmethod | ||
def exec_module(module): | ||
name = module.__spec__.name | ||
if not _imp.is_frozen(name): | ||
raise ImportError('{!r} is not a frozen module'.format(name), | ||
name=name) | ||
code = _call_with_frames_removed(_imp.get_frozen_object, name) | ||
spec = module.__spec__ | ||
name = spec.name | ||
try: | ||
data = spec.loader_state | ||
except AttributeError: | ||
if not _imp.is_frozen(name): | ||
raise ImportError('{!r} is not a frozen module'.format(name), | ||
name=name) | ||
data = None | ||
else: | ||
# We clear the extra data we got from the finder, to save memory. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the loader is one-time use? What happens if you call exec_module() again (e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should work fine. If the data is set then the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added to that comment to clarify. |
||
# Note that if this method is called again (e.g. by | ||
# importlib.reload()) then _imp.get_frozen_object() will notice | ||
# no data was provided and will look it up. | ||
spec.loader_state = None | ||
code = _call_with_frames_removed(_imp.get_frozen_object, name, data) | ||
exec(code, module.__dict__) | ||
|
||
@classmethod | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
In FrozenImporter.find_spec(), we now preserve the information needed in | ||
exec_module() to load the module. This change mostly impacts internal | ||
details, rather than changing the importer's behavior. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.