-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
base: main
Are you sure you want to change the base?
Conversation
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, |
whose definition changed. Module authors may avoid this by explicitly | ||
explicitly setting a *def* as the *token*. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP 123: Summary of changes
)PyType_GetModuleByDef
📚 Documentation preview 📚: https://pep-previews--4453.org.readthedocs.build/pep-0793/