Repository navigation
Revamp sys.lazy_modules #148587
Description
Activity
- added a parent issue
on Apr 14, 2026 I'm waiting for your feedback in this one!
I don't think we should document
sys.lazy_modulesin its current form.PEP 810 already mentions
sys.lazy_modules, so I don't think we can treat the concept as purely private anymore. But the current implementation exposes a live mutabledict[str, set[str]]that is part of the lazy-import machinery, which is stronger than the contract described in the PEP today.I also don't think a plain
mappingproxyis enough here: it would protect the top-level mapping, but the nestedsetvalues would still be mutable. My preference would be:- Update PEP 810 to match the intended public contract.
- Keep the runtime bookkeeping structure private/internal.
- If we want public diagnostics, expose an immutable snapshot instead of the live container.
Since 814 landed, the public shape could be something like
frozendict[str, frozenset[str]]. That gives us a proper read-only introspection API without freezing the internal representation or blessing mutation of interpreter state.Reacted by Bartosz Sławecki and Brittany Reynoso- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errorinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)and removeddocsDocumentation in the Doc dirDocumentation in the Doc dir
on Apr 24, 2026 - changed the title
[-]Document `sys.lazy_modules`[/-][+]Revamp `sys.lazy_modules`[/+]on Apr 24, 2026 expose an immutable snapshot instead of the live container.
@pablogsal, does it have to be
sys.lazy_modules"module-level property" or could it be a function likesys.get_lazy_modules()?
Both preserve the concept, but the function fits more here I believe (snapshots should be lazy + open/close principle i.e. we can extend the function in the future to do more useful things in debugging if needed). My instinct is that it would be good to ship it before beta freeze.- removedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Apr 25, 2026 18 remaining items
This does not need to block beta 1, so moving to deferred-blocker. We can still fix this during the beta, and sooner is better than later, so please try to target b2.
Reacted by Bartosz Sławecki- added a commit that references this issue
on May 19, 2026 - moved this from Todo to Done in Release and Deferred blockers 🚫
on May 19, 2026 I believe we should document this too.
- moved this from Done to In Progress in Release and Deferred blockers 🚫
on May 19, 2026 - added a commit that references this issue
on May 29, 2026 - added a commit that references this issue
on Jun 2, 2026 - added a commit that references this issue
on Jun 2, 2026
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
- StatusShow more project fieldsTodo
Documentation
or make it private, or make it private but expose a mappingproxy.
What are your preferences?
I presume that the PEP must be updated as well (see #145057).
cc @pablogsal @DinoV
Linked PRs
sys.lazy_modulesimmutable #149408sys.lazy_modules#150742sys.lazy_modules(GH-150742) #150795