Skip to content

GH-134160: Prefer multi-phase initialisation in docs #134764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review docs Documentation in the Doc dir needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes skip news topic-C-API
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

3 participants