8000 bpo-45020: Identify which frozen modules are actually aliases. by ericsnowcurrently · Pull Request #28655 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-45020: Identify which frozen modules are actually aliases. #28655

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

Merged
Prev Previous commit
Next Next commit
Allow loader_state.origname to be set already.
  • Loading branch information
ericsnowcurrently committed Oct 5, 2021
commit 900af0f5b4d62acd95300a2d5d89be016ffb2c0b
18 changes: 11 additions & 7 deletions Lib/importlib/_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,14 +831,18 @@ def _setup_module(cls, module):
assert not ispkg or not module.__path__, module.__path__
spec = module.__spec__
assert not ispkg or not spec.submodule_search_locations
assert spec.loader_state is None

origname = vars(module).pop('__origname__', None)
assert origname, 'see PyImport_ImportFrozenModuleObject()'
spec.loader_state = type(sys.implementation)(
data=None,
origname=origname,
)
if spec.loader_state is None:
spec.loader_state = type(sys.implementation)(
data=None,
origname=None,
)
elif not hasattr(spec.loader_state, 'data'):
spec.loader_state.data = None
if not getattr(spec.loader_state, 'origname', None):
origname = vars(module).pop('__origname__', None)
assert origname, 'see PyImport_ImportFrozenModuleObject()'
spec.loader_state.origname = origname

@classmethod
def find_spec(cls, fullname, path=None, target=None):
Expand Down
0