PEP 810: Clarify sys.lazy_modules contract#4954
Open
johnslavik wants to merge 6 commits intopython:mainfrom
Open
PEP 810: Clarify sys.lazy_modules contract#4954johnslavik wants to merge 6 commits intopython:mainfrom
sys.lazy_modules contract#4954johnslavik wants to merge 6 commits intopython:mainfrom
Conversation
Clarify the public introspection contract for ``sys.lazy_modules``: it is a read-only ``frozendict[str, frozenset[str]]`` snapshot rebuilt on each access (via ``sys.__getattr__``), not a live mutable set or dict, so user code cannot mutate the import system's bookkeeping. Add a "Public introspection API" subsection alongside the existing filter API listing, and update prose to reflect the snapshot-on-access contract under "Lazy import mechanism", "Reification", and the subinterpreter note.
Prior commit added a "Public introspection API" subsection plus prose about snapshot semantics, the registry, and sys.__getattr__ rebuild behavior. That overshoots the contract: callers only need to know the type and that it is read-only. Fold the corrected type (``frozendict[str, frozenset[str]]``) into the existing first mention under "Lazy import mechanism", drop the new subsection, and remove the imprecise claim that lazy proxies are "listed in" ``sys.lazy_modules`` (the proxies live in globals; the mapping records each module's lazy imports).
Documentation build overview
714 files changed ·
|
johnslavik
commented
May 4, 2026
| there are still other unreified lazy references to it). When a package is | ||
| reified and submodules in the package were also previously lazily imported, | ||
| those submodules are *not* automatically reified but they *are* added to the | ||
| When the module is reified, its fully qualified name is removed from the |
Member
Author
There was a problem hiding this comment.
Please double check. I'm not sure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of python/cpython#148587.
PEP 123: Summary of changes)