Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
97bdaa2e2e676d63332128cd239b77240190dd38701a0ad16fdf7689385d412e0fe5017221e0e5f68ee87b85a63cdbc611c6e70ccf86dcd5d1b18684e105a95d6af1e017c9321a833ed536370807c947fcddf089ca0500fFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
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. | ||
Member 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. MemberAuthor 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 MemberAuthor 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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.