Skip to content

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

@brittanyrey

Description

@brittanyrey

Bug report

Bug description:

While working on setting up testing infra for lazy_imports=all, I came across this test failure in test_trace. It appears that after importing a submodule, deleting said submodule, and then lazy importing it again--the module doesn't make it's way back into sys.modules.

Example failing code snippet:

import sys
modname = "test.test_lazy_import.data.pkg.bar"
import test.test_lazy_import.data.pkg.bar
del sys.modules[modname]
lazy import test.test_lazy_import.data.pkg.bar  # the issue is also seen when using lazy from
bar.f()
assert modname in sys.modules  # False

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions