Skip to content

Conversation

@hugovk
Copy link

@hugovk hugovk commented Dec 18, 2025

Re: python#142351 (comment)

Code was removed in python@4fd8fe8, also remove from the docs.

@Yhg1s
Copy link

Yhg1s commented Dec 18, 2025

We should document sys.lazy_modules while we're at it, except I'm not sure of the exact semantics...

>>> import sys
>>> lazy import xml
>>> sys.lazy_modules
{}
>>> lazy import xml.etree.ElementTree
>>> sys.lazy_modules
{'xml.etree': {'ElementTree'}, 'xml': {'etree'}}

@DinoV what is going on here? PEP 810 suggests "xml" should have been added to sys.lazy_modules after that first lazy import -- but then it also still refers to sys.lazy_modules as a set, not a dict... Something needs updating :)

@hugovk
Copy link
Author

hugovk commented Dec 18, 2025

We should document sys.lazy_modules while we're at it

@johnslavik Would you like to do this as part of #41?

@johnslavik
Copy link

@johnslavik Would you like to do this as part of #41?

Will do, thanks for the heads up!

@DinoV
Copy link

DinoV commented Dec 18, 2025

We should document sys.lazy_modules while we're at it, except I'm not sure of the exact semantics...

>>> import sys
>>> lazy import xml
>>> sys.lazy_modules
{}
>>> lazy import xml.etree.ElementTree
>>> sys.lazy_modules
{'xml.etree': {'ElementTree'}, 'xml': {'etree'}}

@DinoV what is going on here? PEP 810 suggests "xml" should have been added to sys.lazy_modules after that first lazy import -- but then it also still refers to sys.lazy_modules as a set, not a dict... Something needs updating :)

Yep, we need to update the PEP. I had discussed this with Pablo offline and he suggested we make sure to collect all of the changes and do one final update as we'll need to get SC approval.

We already have a set which we use to track the lazy_modules internally as we need to publish imported lazy submodules on the parent module when they are imported. So we could basically maintain a secondary dict and update that as the PEP describes or we can expose what we're actually using for the source of truth for decisions and the latter seems more valuable. So lazy_modules is now a dict from parent module to child modules that have been imported from it.

Here's my initial attempt to update the PEP DinoV/peps@7a78bf2 (it also fixes one other issue I caught while reviewing it).

@DinoV DinoV merged commit b437afb into LazyImportsCabal:lazy Dec 18, 2025
@hugovk hugovk deleted the 3.15-lazy-rm-get_lazy_modules branch December 23, 2025 11:32
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