Skip to content

gh-151408: Re-register submodules in sys.modules on lazy re-import#151411

Closed
bhuvi27 wants to merge 1 commit into
python:mainfrom
bhuvi27:gh-151408-fix-lazy-reimport
Closed

gh-151408: Re-register submodules in sys.modules on lazy re-import#151411
bhuvi27 wants to merge 1 commit into
python:mainfrom
bhuvi27:gh-151408-fix-lazy-reimport

Conversation

@bhuvi27

@bhuvi27 bhuvi27 commented Jun 12, 2026

Copy link
Copy Markdown

Fixes #151408

Deleting a submodule from sys.modules and then re-resolving it via lazy import returned the module object still cached on the parent package but did not put it back in sys.modules.

Register the submodule in sys.modules again when import-from or module getattr finds it on the parent and its name matches. Tests in test_lazy_import.

When a submodule is removed from sys.modules but still cached on its
parent package, lazy import reification returned the stale module
without restoring sys.modules. Register the module again when import
or attribute lookup resolves a submodule whose __name__ matches.
@ZeroIntensity

Copy link
Copy Markdown
Member

Closing in favor of #151412

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When re-importing a submodule lazily after removing it, it's never added back to sys.modules.

2 participants