Skip to content

Lazy imports fail to reload an unloaded parent package #162346

Open

Description

@tonghuaroot

Bug description:

With all imports made lazy, the existing regression test for a relative import
from an unloaded package fails:

./python -X lazy_imports=all -m test test_import -m test_import_from_unloaded_package -q

It raises KeyError: 'package2'. The test passes without
-X lazy_imports=all.

package2.submodule1 removes package2 from sys.modules and then imports
another submodule relatively. The eager import reloads the missing parent, but
the lazy import tries to bind the child while the parent is still absent.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions