Skip to content

Conversation

@AA-Turner
Copy link
Member

@AA-Turner AA-Turner commented May 27, 2025

Comment on lines -287 to +273
An alternate way to specify extensions is to request "multi-phase initialization".
The preferred method to specify extensions is to request "multi-phase initialization".
Extension modules created this way behave more like Python modules: the
initialization is split between the *creation phase*, when the module object
is created, and the *execution phase*, when it is populated.
The distinction is similar to the :py:meth:`!__new__` and :py:meth:`!__init__` methods
of classes.
Unlike modules created using single-phase initialization, these modules are not
singletons: if the *sys.modules* entry is removed and the module is re-imported,
a new module object is created, and the old module is subject to normal garbage
collection -- as with Python modules.
Unlike modules created using the legacy single-phase initialization mechanism,
these modules are not singletons: if the *sys.modules* entry is removed and
the module is re-imported, a new module object is created, and the old module
is subject to normal garbage collection -- as with Python modules.
Copy link
Member

Choose a reason for hiding this comment

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

I think this shouldn't be a comparison. If we're calling single-phase “legacy” (which finally seems to be the cunsensus), then this section should describe what modules are, and the single-phase section should describe the eldritch weirdness of that method.
Should I try to reword it that way? (I'd like to avoid merge conflicts.)

Copy link
Member Author

Choose a reason for hiding this comment

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

There is existing mention of single-phase as 'legacy', though admittedly in a niche location: https://docs.python.org/3/c-api/init.html#c.PyInterpreterConfig.check_multi_interp_extensions

Copy link
Member Author

Choose a reason for hiding this comment

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

Should I try to reword it that way? (I'd like to avoid merge conflicts.)

@encukou feel free to push to this branch.

@encukou
Copy link
Member

encukou commented Jun 4, 2025

I think this chapter needs to be split. Extension module definition should not be PyModule docs (“concrete objects layer”), and it's grown to fill its own page.

I couldn't resolve the conflicts cleanly, so I rebased.
Continued in #135126.

@encukou
Copy link
Member

encukou commented Jun 4, 2025

(I see closing this PR as the equivalent to pushing to the branch.)

@encukou encukou closed this Jun 4, 2025
@AA-Turner AA-Turner removed needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Aug 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants