Skip to content

Docs Examples Focus on Outdated Single-Phase Init Modules and Static Types #134160

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
ericsnowcurrently opened this issue May 17, 2025 · 7 comments
Labels
docs Documentation in the Doc dir

Comments

@ericsnowcurrently
Copy link
Member

ericsnowcurrently commented May 17, 2025

A variety of pages show examples (or provide explanations) around single-phase init modules and static types, but should focus on the newer, recommended alternatives. For example:

For reference:

Linked PRs

@ericsnowcurrently ericsnowcurrently added the docs Documentation in the Doc dir label May 17, 2025
@neonene
Copy link
Contributor

neonene commented May 19, 2025

.. note::
Unlike our ``spam`` example, ``xxmodule`` uses *multi-phase initialization*
(new in Python 3.5), where a PyModuleDef structure is returned from
``PyInit_spam``, and creation of the module is left to the import machinery.
For details on multi-phase initialization, see :PEP:`489`.

Should alternatives be explained according to xxmodule? I'm not sure what "xx" officially means, though. Or, maybe new eggs examples, leaving/removing the legacy page and xxmodule.c?

@ericsnowcurrently
Copy link
Member Author

Good point. I'm not quite sure. Keeping the old tutorials around makes sense in some ways, but perhaps not in a different file somehow or maybe just not listed in the index?

As to the xxmodule it may make sense to add a new equivalent for multi-phase init. @encukou might have some thoughts on this.

@ericsnowcurrently
Copy link
Member Author

Ideally we would update the docs back to 3.12 at least.

@encukou
Copy link
Member

encukou commented May 21, 2025

Thank you for doing this! Sorry that I can't give this my full attention right now.

xxmodule: Use xxlimited instead.
Backporting: AFAIK, stats show that most people go to the current version. IMO, at this point, backporting big changes to 3.14 is fine.

AA-Turner added a commit that referenced this issue May 26, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 26, 2025
…onGH-134296)

(cherry picked from commit 96905bd)

Co-authored-by: neonene <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 26, 2025
…onGH-134296)

(cherry picked from commit 96905bd)

Co-authored-by: neonene <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
AA-Turner added a commit that referenced this issue May 26, 2025
…134296) (#134753)

gh-134160: Use multi-phase init in documentation examples (GH-134296)
(cherry picked from commit 96905bd)

Co-authored-by: neonene <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
AA-Turner added a commit that referenced this issue May 26, 2025
…134296) (#134754)

gh-134160: Use multi-phase init in documentation examples (GH-134296)
(cherry picked from commit 96905bd)

Co-authored-by: neonene <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
@encukou
Copy link
Member

encukou commented May 27, 2025

The docs are now incorrect :(
I'm sorry that I missed the review window; I was planning to take a look next week but didn't announce that.
Would it make sense to revert the 3.13 backport at least?

encukou added a commit to encukou/cpython that referenced this issue May 27, 2025
encukou added a commit to encukou/cpython that referenced this issue May 27, 2025
AA-Turner added a commit that referenced this issue May 28, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 28, 2025
(cherry picked from commit 469a564)

Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 28, 2025
(cherry picked from commit 469a564)

Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
AA-Turner added a commit that referenced this issue May 28, 2025
…134827)

gh-134160: Block multiple module initialization (GH-134773)
(cherry picked from commit 469a564)

Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
AA-Turner added a commit that referenced this issue May 28, 2025
…134828)

gh-134160: Block multiple module initialization (GH-134773)
(cherry picked from commit 469a564)

Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
encukou added a commit that referenced this issue May 30, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 30, 2025
…rpreters (pythonGH-134775)

(cherry picked from commit eb145fa)

Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
AA-Turner added a commit that referenced this issue May 31, 2025
…erpreters (GH-134775) (#134932)

gh-134160: Improve multi-phase init note on isolation & subinterpreters (GH-134775)

(cherry picked from commit eb145fa)

Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 31, 2025
…rpreters (pythonGH-134775)

(cherry picked from commit eb145fa)

Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
@neonene
Copy link
Contributor

neonene commented Jun 2, 2025

@encukou Could xxlimited have a m_free function or update the comment below?

cpython/Modules/xxlimited.c

Lines 436 to 437 in ac75110

/* m_free is not necessary here: xx_clear clears all references,
* and the module state is deallocated along with the module.

For me, xx_clear is not called if xx_modexec fails with the module not being held by heaptypes.

encukou added a commit to encukou/cpython that referenced this issue Jun 4, 2025
…asize multi-phase init

Document behaviour of single-phase init. Call it "legacy".

Reorganize PyModule docs.

Move PyInit_modulename docs from the tutorial to reference documentation.

Move PyMODINIT_FUNC docs from generic macros to the new page.

Add doc stubs for `PYTHON_API_VERSION` & `PYTHON_ABI_VERSION`

Remove incorrect refcounts.dat entry for `PyModuleDef_Init`.
This removes the "Return value: Borrowed reference." note.
Instead, note that the function sometimes returns a borrowed reference,
sometimes as strong one.
(IMO, it's best to not think of `PyModuleDef` as a `PyObject` at all,
and act like it can't be reference-counted.)

Co-authored-by: Adam Turner <[email protected]>
@encukou encukou marked this as a duplicate of #70702 Jun 4, 2025
encukou added a commit that referenced this issue Jun 4, 2025
…erpreters (GH-134775) (GH-134983)

(cherry picked from commit eb145fa)

Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
@encukou
Copy link
Member

encukou commented Jun 5, 2025

@encukou Could xxlimited have a m_free function or update the comment below?

Yes: #135174

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 6, 2025
…ed (pythonGH-135174)

(cherry picked from commit 1adca08)

Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: neonene <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 6, 2025
…ed (pythonGH-135174)

(cherry picked from commit 1adca08)

Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: neonene <[email protected]>
encukou added a commit that referenced this issue Jun 6, 2025
…ted (GH-135174) (GH-135213)

gh-134160: Use PyModuleDef.m_free in the example module xxlimited (GH-135174)
(cherry picked from commit 1adca08)

Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: neonene <[email protected]>
encukou added a commit that referenced this issue Jun 7, 2025
…ted (GH-135174) (GH-135214)

gh-134160: Use PyModuleDef.m_free in the example module xxlimited (GH-135174)
(cherry picked from commit 1adca08)

Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: neonene <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
Status: Todo
Development

No branches or pull requests

3 participants