Skip to content

PEP 793: Updates from discussion & implementation #4453

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

encukou
Copy link
Member

@encukou encukou commented Jun 7, 2025

  • Change is either:
    • To a Draft PEP
    • To an Accepted or Final PEP, with Steering Council approval
    • To fix an editorial issue (markup, typo, link, header, etc)
  • PR title prefixed with PEP number (e.g. PEP 123: Summary of changes)

  • Add a shim to implement the old hook in terms of the new one
  • Soft-deprecate the old hook
  • Allow tokens for PyType_GetModuleByDef

📚 Documentation preview 📚: https://pep-previews--4453.org.readthedocs.build/pep-0793/

@encukou encukou requested review from benjaminp, vstinner and a team as code owners June 7, 2025 14:59
@@ -26,6 +26,10 @@ To make this viable, we also specify new module slot types to replace

We also add an API for defining modules from slots dynamically.

The existing API (``PyInit_*``) is soft-deprecated.
(That is: it will continue to work without warnings, and it'll fe fully
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
(That is: it will continue to work without warnings, and it'll fe fully
(That is: it will continue to work without warnings, and it'll be fully

@@ -264,6 +289,10 @@ If specified, using a new ``Py_mod_token`` slot, the module token must:

(Typically, it should point to a static constant.)

When the address of a ``PyModuleDef`` is used as as a module's token,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
When the address of a ``PyModuleDef`` is used as as a module's token,
When the address of a ``PyModuleDef`` is used as a module's token,

Comment on lines +431 to +432
whose definition changed. Module authors may avoid this by explicitly
explicitly setting a *def* as the *token*.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
whose definition changed. Module authors may avoid this by explicitly
explicitly setting a *def* as the *token*.
whose definition changed. Module authors may avoid this by explicitly
setting a *def* as the *token*.

#. Scan your code for uses of ``PyType_GetModuleByDef``, and replace them by
``PyType_GetModuleByToken``.
#. Optionally, scan your code for uses of ``PyType_GetModuleByDef``,
and replace them by ``PyType_GetModuleByToken``.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
and replace them by ``PyType_GetModuleByToken``.
and replace them with ``PyType_GetModuleByToken``.

Later in this guide, you'll set the token to *be* the existing
``PyModuleDef`` structure.

(You may skip this step if targetting Python versions that don't expose
``PyType_GetModuleByToken``, since ``PyType_GetModuleByDef`` is
backwards-compatible. )
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
backwards-compatible. )
backwards-compatible.)


#. If the existing ``PyModuleDef`` struct is used *only* for ``Py_mod_token``
and/or ``PyType_GetModuleByToken``, you may remove the ``Py_mod_token``
line and replace ``&your_module_def`` by ``module_slots`` everywhere else.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
line and replace ``&your_module_def`` by ``module_slots`` everywhere else.
line and replace ``&your_module_def`` with ``module_slots`` everywhere else.

Backwards compatibility shim
----------------------------

It is possible to write generic function that implements the “old” export
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
It is possible to write generic function that implements the “old” export
It is possible to write a generic function that implements the “old” export

- Any ``Py_mod_token`` must be set to ``&module_def_and_token``, defined here.

It also passes ``NULL`` as *spec* to the ``PyModExport`` export hook.
A proper implementation would pass ``None`` instead, .
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
A proper implementation would pass ``None`` instead, .
A proper implementation would pass ``None`` instead.

@@ -550,6 +653,7 @@ Possible Future Directions

These ideas are out of scope for *this* proposal.


Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

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.

2 participants