Skip to content

gh-140550: Initial implementation of PEP 793 – PyModExport - #140556

Merged
encukou merged 87 commits into
python:mainfrom
encukou:modexport-rebased
Nov 5, 2025
Merged

encukou merged 87 commits into
python:mainfrom
encukou:modexport-rebased

Conversation

@encukou

@encukou encukou commented Oct 24, 2025 •

Copy link
Copy Markdown
Member

This adds the initial implementation of PEP-793.
See the issue for follow-up tasks.

@encukou encukou left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thank you for the initial review!

Yes, but there's a lot of tests. And I've also renamed things that changed semantics, so unrelated changes/backports will conflict or fail to build, rather than merge cleanly at the Git level but be subtly broken.

Comment on lines +1 to +2
import unittest
import types

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I couldn't find this in PEP 8.

Comment thread Lib/test/test_sys.py Resolved
Comment thread Modules/_testcapi/heaptype.c Resolved
Comment thread Objects/moduleobject.c Resolved
Comment thread Objects/moduleobject.c Resolved
@encukou

encukou commented Oct 28, 2025

Copy link
Copy Markdown
Member Author

!buildbot AMD64.FreeBSD.Refleaks

@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @encukou for commit 01d52ba 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F140556%2Fmerge

The command will test the builders whose names match following regular expression: AMD64.FreeBSD.Refleaks

The builders matched are:

  • AMD64 FreeBSD Refleaks PR
Comment thread Objects/moduleobject.c Resolved
@encukou

encukou commented Oct 29, 2025

Copy link
Copy Markdown
Member Author

Do you plan to add documentation in a separated PR?

Yes. There's a lot to add since the PEP calls for soft-deprecation of PyInit_; see the issue.

Comment thread Include/internal/pycore_moduleobject.h Resolved
Comment thread Include/internal/pycore_moduleobject.h Resolved
Comment thread Include/internal/pycore_moduleobject.h Resolved
encukou and others added 2 commits November 3, 2025 14:52
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Comment thread Python/import.c Resolved

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Just please move _PyModule_GetGCHooks() to pycore_moduleobject.h.

Comment thread Include/internal/pycore_moduleobject.h Outdated
static inline PyModuleDef *_PyModule_GetDefOrNull(PyObject *arg) {
PyModuleObject *mod = _PyModule_CAST(arg);
if (mod->md_token_is_def) {
return (PyModuleDef *)((PyModuleObject *)mod)->md_token;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
return (PyModuleDef *)((PyModuleObject *)mod)->md_token;
return (PyModuleDef *)mod->md_token;
Comment thread Include/moduleobject.h Resolved

PyMODINIT_FUNC
FUNC_NAME(MODULE_NAME)(void)
INITFUNC_NAME(MODULE_NAME)(void)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it really needed to define a PyInit function if a modexport function is defined with slots? Developers may reuse this code as an example.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for the catch! I think I had some platform-specific issues with the current version of setuptools. I added this to the TODO list in the issue; I'll get to it in a later PR.

Comment thread Objects/moduleobject.c Resolved
@encukou

encukou commented Nov 5, 2025

Copy link
Copy Markdown
Member Author

Thank you for the review!

@encukou
encukou merged commit 589a03a into python:main Nov 5, 2025
@encukou
encukou deleted the modexport-rebased branch November 5, 2025 11:31
@vstinner

vstinner commented Nov 5, 2025

Copy link
Copy Markdown
Member

Congrats :-)

@vstinner

vstinner commented Nov 5, 2025

Copy link
Copy Markdown
Member

make check-limited-abi does now fail on the main branch:

./python -E ./Tools/build/generate-build-details.py `cat pybuilddir.txt`/build-details.json
Checked 115 modules (37 built-in, 77 shared, 1 n/a on linux-x86_64, 0 disabled, 0 missing, 0 failed on import)
./python ./Tools/build/stable_abi.py --all
File /home/vstinner/python/main/Doc/data/stable_abi.dat differs from expected!
--- /home/vstinner/python/main/Doc/data/stable_abi.dat
+++ <expected>
@@ -979,14 +979,6 @@
 type,Py_buffer,3.11,,full-abi
 type,Py_intptr_t,3.2,,
 macro,Py_mod_abi,3.15,,
-macro,Py_mod_doc,3.15,,
-macro,Py_mod_methods,3.15,,
-macro,Py_mod_name,3.15,,
-macro,Py_mod_state_clear,3.15,,
-macro,Py_mod_state_free,3.15,,
-macro,Py_mod_state_size,3.15,,
-macro,Py_mod_state_traverse,3.15,,
-macro,Py_mod_token,3.15,,
 macro,Py_mp_ass_subscript,3.2,,
 macro,Py_mp_length,3.2,,
 macro,Py_mp_subscript,3.2,,

I created #141056 to fix the issue.

@encukou

encukou commented Nov 5, 2025

Copy link
Copy Markdown
Member Author

Thank you!

StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
…honGH-140556)

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants