Skip to content

[3.15] gh-148587: Make sys.lazy_modules match PEP and keep internal lazy submodules tra…#150014

Open
DinoV wants to merge 2 commits into
python:3.15from
DinoV:lazy_modules
Open

[3.15] gh-148587: Make sys.lazy_modules match PEP and keep internal lazy submodules tra…#150014
DinoV wants to merge 2 commits into
python:3.15from
DinoV:lazy_modules

Conversation

@DinoV
Copy link
Copy Markdown
Contributor

@DinoV DinoV commented May 18, 2026

The PEP initially set sys.lazy_modules was to be a set of the lazily imported things. At some point it seemed that having our internal tracking for publishing submodules to parent modules when they're imported could be combined with this. But this means that data the interpreter is making decisions on is now immutable. This goes back to having a separate set for the lazy modules which is user visible but has no impact on how lazy imports are evaluated or executed.

This is one possible approach - another one would be to make it a function and calculate the set and return it per-call. Then it would be backed by our normal internal data.

We could also make it a function and keep tracking both sets of data as this PR does and then that'd give us the ability in the future to lazily calculate the data.

@DinoV DinoV changed the title Make sys.lazy_modules match PEP and keep internal lazy submodules tra… gh-148587: Make sys.lazy_modules match PEP and keep internal lazy submodules tra… May 18, 2026
@DinoV DinoV changed the title gh-148587: Make sys.lazy_modules match PEP and keep internal lazy submodules tra… [3.15] gh-148587: Make sys.lazy_modules match PEP and keep internal lazy submodules tra… May 18, 2026
Copy link
Copy Markdown
Member

@Yhg1s Yhg1s left a comment

Choose a reason for hiding this comment

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

I think this approach makes sense...

PyObject *lazy_importing_modules;
// The set stored in sys.lazy_modules if values that have been
// lazily imported. This value is only for debugging/introspection
// purposes and is not used at runtime.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// purposes and is not used at runtime.
// purposes and is not used by the runtime.

Comment on lines +356 to +358
// Submodules that have been imported lazily from modules which have
// been imported lazily. When the module is imported we need to add
// a LazyImportObject which refers to the submodule on the module.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// Submodules that have been imported lazily from modules which have
// been imported lazily. When the module is imported we need to add
// a LazyImportObject which refers to the submodule on the module.
// A dict mapping package names to a set of submodule names that
// have been imported lazily from packages which have been imported
// lazily. When the package is reified we need to add a
// LazyImportObject which refers to the submodule on the module.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants