gh-148588: Document __lazy_modules__#148590
Open
johnslavik wants to merge 13 commits intopython:mainfrom
Open
Conversation
…y imports Add documentation for the __lazy_modules__ module attribute in two places: - Doc/reference/simple_stmts.rst: new subsection under the lazy imports section explaining the compatibility mode, its semantics (module-scope only, overridden by -X lazy_imports=none), and a usage example. - Doc/reference/datamodel.rst: new module.__lazy_modules__ attribute entry with a cross-reference to the detailed explanation in simple_stmts. Also extend the What's New in Python 3.15 lazy-imports entry with a short paragraph and example demonstrating __lazy_modules__.
… docs entry Replace bare __lazy_modules__ in the 3.15.0a8 NEWS entry with :attr:`module.__lazy_modules__` to link to the new attribute documentation. Remove the separate docs NEWS entry; the archive entry serves as the record.
Replace 'migrating a large existing codebase' with the more accurate use case: supporting Python <3.15 while leveraging lazy imports on 3.15+.
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.
I'll need some info here, cc @pablogsal @Yhg1s
The PEP reads as if
__lazy_modules__must implement__contains__. The actual implementation supports any iterable, because it uses the classic membership test.Question: Is it an implementation detail of CPython to support objects beyond containers in
__lazy_modules__, and non-containers aren't supported, or do we support any iterable for__lazy_modules__?Right now I can assign a generator or an old-style
__getitem__-based sequence to__lazy_modules__and CPython will walk it to check membership. Question is whether it's just a CPython thing.EDIT: ...Hmmm now that I think about it, this makes no sense: a
__lazy_modules__generator will be empty after the firstimport, rendering all subsequent imports eager. I believe we shouldn't support anything beyond containers. Maybe we could even do this at the runtime level, but maybe if you put a generator to__lazy_modules__you deserve anything that happens to you.__lazy_modules__#148588📚 Documentation preview 📚: https://cpython-previews--148590.org.readthedocs.build/