GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Accessing one lazily imported submodule (`lazy import pkg.a`) also imports a later imported `pkg.b` · Issue #158140 · python/cpython

Accessing one lazily imported submodule (lazy import pkg.a) also imports a later imported pkg.b #158140

New issue
Copy link
New issue
Copy link
Closed
#158521
Closed
Accessing one lazily imported submodule (lazy import pkg.a) also imports a later imported pkg.b#158140
#158521
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)release-blockertopic-lazy-importstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@msullivan
msullivan
opened on Sep 24, 2026
Issue body actions

Bug report

Bug description:

If we do a lazy import of two submodules in the same package tree (like pkg.a and pkg.b), then accessing pkg.a will cause pkg.b to get imported first. I think this is because pkg gets bound specifically to a lazy_import object for pkg.b. (In fact, just accessing pkg also imports pkg.b).

main.py:

lazy import pkg.a
lazy import pkg.b

print(globals()['pkg'])  # <lazy_import 'pkg.b'>

pkg.a  # triggers import of pkg (of course), pkg.b (sketchy!!), pkg.a (of course)
pkg/
├── __init__.py   # print("pkg")
├── a.py          # print("pkg.a")
└── b.py          # print("pkg.b")

This prints:

<lazy_import 'pkg.b'>
pkg
pkg.b
pkg.a

CPython versions tested on:

3.15

Operating systems tested on:

Linux

Linked PRs

  • gh-158140: Do not eagerly import sibling submodules on lazy import #158491
  • gh-158140: Resolve lazily imported sibling submodules independently #158521
  • [3.15] gh-158140: Resolve lazily imported sibling submodules independently (GH-158521) #158613
  • gh-158140: Resolve lazy submodules independently with custom import hooks #158815

Activity

  1. msullivan
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Sep 24, 2026
  2. aisk
    added
    topic-lazy-imports
    on Sep 25, 2026
  3. StanFromIreland
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Sep 25, 2026
  4. pablogsal
    added
    release-blocker
    on Sep 30, 2026
  5. github-project-automation
    added this to Release and Deferred blockers 🚫on Sep 30, 2026
  6. github-project-automation
    moved this to Todo in Release and Deferred blockers 🚫on Sep 30, 2026
  7. pablogsal
    added 2 commits that reference this issue on Oct 1, 2026

    pythongh-158140: Resolve lazily imported sibling submodules independe…

    56babbc

    pythongh-158140: Resolve lazy siblings through the pending-child regi…

    4e83bfa
  8. Yhg1s
    added a commit that references this issue on Oct 2, 2026

    gh-158140: Resolve lazily imported sibling submodules independently (#…

    00a1c3a
  9. Yhg1s
    closed this as completedin #158521on Oct 2, 2026
  10. github-project-automation
    moved this from Todo to Done in Release and Deferred blockers 🚫on Oct 2, 2026
  11. hugovk
    added a commit that references this issue on Oct 2, 2026

    [3.15] gh-158140: Resolve lazily imported sibling submodules independ…

    03bb26f
  12. pablogsal
    added 4 commits that reference this issue on Oct 5, 2026

    pythongh-158140: Resolve lazy submodules independently with custom im…

    4f72c54

    pythongh-158140: Resolve lazy submodules independently with custom im…

    979f879

    pythongh-158140: Resolve lazy submodules independently with custom im…

    63a9bca

    pythongh-158140: Resolve lazy submodules independently with custom im…

    200bac8
  13. Kronuz
    added a commit that references this issue on Oct 5, 2026

    [3.15] pythongh-158140: Resolve lazily imported sibling submodules in…

    bcb3aa6
  14. ambv
    added a commit that references this issue on Oct 20, 2026

    pythongh-158140: Resolve lazy submodules independently with custom im…

    94b13f3
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

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)release-blockertopic-lazy-importstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    • Release and Deferred blockers 🚫
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402520 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.