Skip to content

Revamp sys.lazy_modules #148587

Closed
Closed

Activity

  1. self-assigned this
    on Apr 14, 2026
  2. added
    docs
    on Apr 14, 2026
  3. johnslavik commented on Apr 14, 2026

    @johnslavik
    MemberAuthor

    I'm waiting for your feedback in this one!

  4. pablogsal commented on Apr 24, 2026

    @pablogsal
    Member

    I don't think we should document sys.lazy_modules in 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 mutable dict[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 mappingproxy is enough here: it would protect the top-level mapping, but the nested set values would still be mutable. My preference would be:

    1. Update PEP 810 to match the intended public contract.
    2. Keep the runtime bookkeeping structure private/internal.
    3. 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.

  5. pablogsal commented on Apr 24, 2026

    @pablogsal
    Member
  6. added
    type-bug
    interpreter-core
    and removed
    docs
    on Apr 24, 2026
  7. changed the title [-]Document `sys.lazy_modules`[/-] [+]Revamp `sys.lazy_modules`[/+] on Apr 24, 2026
  8. johnslavik commented on Apr 25, 2026

    @johnslavik
    MemberAuthor

    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 like sys.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.

  9. removed
    type-bug
    on Apr 25, 2026
  10. 18 remaining items

  11. hugovk commented on May 7, 2026

    @hugovk
    Member

    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.

  12. added a commit that references this issue on May 19, 2026
  13. johnslavik commented on May 19, 2026

    @johnslavik
    MemberAuthor

    I believe we should document this too.

  14. added
    3.15
    on May 22, 2026
  15. added a commit that references this issue on May 29, 2026
  16. added a commit that references this issue on Jun 2, 2026
  17. added a commit that references this issue on Jun 2, 2026
  18. added a commit that references this issue on Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.15deferred-blockerinterpreter-coretopic-lazy-importstype-feature

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions