Skip to content

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

Merged
DinoV merged 3 commits into
python:3.15from
DinoV:lazy_modules
May 19, 2026
Merged

[3.15] gh-148587: Make sys.lazy_modules match PEP and keep internal lazy submodules tra…#150014
DinoV merged 3 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...

Comment thread Include/internal/pycore_interp_structs.h Outdated
Comment thread Include/internal/pycore_interp_structs.h Outdated
@DinoV DinoV merged commit 94c8bac into python:3.15 May 19, 2026
54 checks passed
@hugovk
Copy link
Copy Markdown
Member

hugovk commented May 19, 2026

This went directly into 3.15, does it need forward porting to main?

@johnslavik
Copy link
Copy Markdown
Member

johnslavik commented May 19, 2026

This went directly into 3.15, does it need forward porting to main?

Correct, thank you for catching that.

Great work @DinoV! This was the cleanest idea.
cc @pablogsal

@johnslavik johnslavik assigned DinoV and unassigned DinoV May 19, 2026
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