Skip to content

PEP 810: Clarify sys.lazy_modules contract#4954

Open
johnslavik wants to merge 6 commits intopython:mainfrom
johnslavik:update-lazy-modules-contract
Open

PEP 810: Clarify sys.lazy_modules contract#4954
johnslavik wants to merge 6 commits intopython:mainfrom
johnslavik:update-lazy-modules-contract

Conversation

@johnslavik
Copy link
Copy Markdown
Member

@johnslavik johnslavik commented May 4, 2026

Part of python/cpython#148587.

  • Change is either:
    • To a Draft PEP
    • To an Accepted or Final PEP, with Steering Council approval
    • To fix an editorial issue (markup, typo, link, header, etc)
  • PR title prefixed with PEP number (e.g. PEP 123: Summary of changes)

johnslavik added 2 commits May 5, 2026 00:08
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).
@read-the-docs-community
Copy link
Copy Markdown

read-the-docs-community Bot commented May 4, 2026

Documentation build overview

📚 pep-previews | 🛠️ Build #32534676 | 📁 Comparing b668744 against latest (b8653e0)

  🔍 Preview build  

714 files changed · ± 714 modified

± Modified

@johnslavik johnslavik marked this pull request as draft May 4, 2026 23:27
@johnslavik johnslavik marked this pull request as ready for review May 4, 2026 23:36
Comment thread peps/pep-0810.rst
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
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please double check. I'm not sure.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants