Skip to content

gh-162346: Fix lazy import from an unloaded package - #162347

Open
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:fix-lazy-unloaded-parent
Open

tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:fix-lazy-unloaded-parent

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

When a submodule removes its parent package from sys.modules, a relative
import normally reloads the parent. With lazy imports enabled,
_find_and_load_unlocked() instead raised KeyError while binding the child.

Reload the missing parent before binding the child, and add a regression test
for lazy imports.

Reimport a missing parent package before binding a loaded submodule. This keeps lazy imports consistent with the existing eager import behavior.
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.

1 participant