GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-140550: Initial implementation of PEP 793 – PyModExport by encukou · Pull Request #140556 · python/cpython

Conversation

@encukou

@encukou encukou commented Oct 24, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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

  • Issue: Implement PEP 793 – PyModExport #140550

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
encukou added 30 commits October 24, 2025 17:01
@encukou
Define PyMODEXPORT_FUNC
4ad95be
@encukou
Add new state to module object
c53650d
@encukou
Make sure the module def matches the state
9564e20
@encukou
Add simple test case
05a87c3
@encukou
Add new slot definitions
57c4f1e
@encukou
Modules are bigger sue me
956c59a
@encukou
Add a test for PyModule_FromSlotsAndSpec
14a66d2
@encukou
Add PyModule_FromSlotsAndSpec (empty for now)
72a27f5
@encukou
Add module test
b54293b
@encukou
Fill in enough of a PyModuleDef to pass to common machinery
fcc68f8
@encukou
Pass in a spec
3ab607e
@encukou
Rename field which can now be NULL
35d7d51
@encukou
Common implementation for PyModule_From{Def,Slots}AndSpec
6fbbc18
This uses a "def-like" structure: a PyModuleDef* that's not a valid
Python object.
@encukou
Add test for Py_mod_name slot
7207e07
@encukou
Handle Py_mod_name
8d4d264
@encukou
Test repeated slot
bd61e5b
@encukou
Test Py_mod_name with a def
d638abf
@encukou
Py_mod_doc
b24e6a6
@encukou
Disallow NULL slot value
756cbff
@encukou
Test repeats and NULL for all new slots
320de14
@encukou
Add PyModule_GetSize
4d88cf3
@encukou
Test size
a1d3c15
@encukou
Handle size
7fcee67
@encukou
Test new slots with PyModuleDef
9fd1e7e
@encukou
Py_mod_methods
fd95984
@encukou
GC hooks
748e18f
@encukou
Py_mod_token
1101f55
@encukou
Py_mod_exec
488eae7
@encukou
Clean up slot-handling a bit
f9d0dde
@encukou
Py_mod_create
020dcc6
encukou
encukou commented Oct 28, 2025
View reviewed changes

@encukou encukou left a comment

Copy link
Copy Markdown
Member Author

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.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_capi/test_module.py
Comment on lines +1 to +2
import unittest
import types

@encukou encukou Oct 28, 2025

Copy link
Copy Markdown
Member Author

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.

I couldn't find this in PEP 8.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_sys.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/_testcapi/heaptype.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Objects/moduleobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Objects/moduleobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@encukou

encukou commented Oct 28, 2025

Copy link
Copy Markdown
Member Author

!buildbot AMD64.FreeBSD.Refleaks

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Oct 28, 2025

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
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vstinner
vstinner reviewed Oct 28, 2025
View reviewed changes
Comment thread Objects/moduleobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

encukou added 2 commits October 29, 2025 09:02
@encukou
Correct logic
ba6e602
@encukou
Merge in the main branch
d26e9b7
@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.

vstinner reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303
kumaraditya303 reviewed Nov 2, 2025
View reviewed changes
Comment thread Include/internal/pycore_moduleobject.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303
kumaraditya303 reviewed Nov 2, 2025
View reviewed changes
Comment thread Include/internal/pycore_moduleobject.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303
kumaraditya303 reviewed Nov 2, 2025
View reviewed changes
Comment thread Include/internal/pycore_moduleobject.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

encukou and others added 2 commits November 3, 2025 14:52
@encukou @kumaraditya303
Get the spaces just right
26b57f2
Co-authored-by: Kumar Aditya <[email protected]>
@encukou
Merge branch 'main' into modexport-rebased
66e8309
kumaraditya303
kumaraditya303 reviewed Nov 3, 2025
View reviewed changes
Comment thread Python/import.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@encukou
_PyModule_GetDefOrNull never raises
928f23b
vstinner
vstinner approved these changes Nov 4, 2025
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

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.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
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;

@vstinner vstinner Nov 4, 2025

Copy link
Copy Markdown
Member

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.

Suggested change
return (PyModuleDef *)((PyModuleObject *)mod)->md_token;
return (PyModuleDef *)mod->md_token;

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Include/moduleobject.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_cext/extension.c

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

@vstinner vstinner Nov 4, 2025

Copy link
Copy Markdown
Member

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.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@encukou encukou Nov 4, 2025

Copy link
Copy Markdown
Member Author

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.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Objects/moduleobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Nov 4, 2025
encukou and others added 4 commits November 4, 2025 12:52
@encukou
Merge in the main branch
4f3712f
@encukou
Remove _PyModule_GetGCHooks; get the hooks directly via internal API
55ae793
@vstinner @encukou
Style fixes
1e6b18c
@encukou
Remove unused variables
4d58846
@encukou

encukou commented Nov 5, 2025

Copy link
Copy Markdown
Member Author

Thank you for the review!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@encukou
encukou merged commit 589a03a into python:main Nov 5, 2025
46 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label 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 :-)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@encukou

encukou commented Nov 5, 2025

Copy link
Copy Markdown
Member Author

Thank you!

vstinner reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
@encukou @vstinner
@kumaraditya303 @StanFromIreland
pythongh-140550: Initial implementation of PEP 793 – PyModExport (pyt…
7e30dee
…honGH-140556)

Co-authored-by: Victor Stinner <[email protected]>
Co-authored-by: Kumar Aditya <[email protected]>
@ngoldbaum ngoldbaum mentioned this pull request Jan 15, 2026
PyModule_FromSlotsAndSpec and PyModule_GetToken exposed without named parameters #143883
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner approved these changes
@kumaraditya303 kumaraditya303 kumaraditya303 left review comments
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@ncoghlan ncoghlan Awaiting requested review from ncoghlan ncoghlan is a code owner
@warsaw warsaw Awaiting requested review from warsaw warsaw is a code owner
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner
@erlend-aasland erlend-aasland Awaiting requested review from erlend-aasland erlend-aasland is a code owner
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner
@emmatyping emmatyping Awaiting requested review from emmatyping emmatyping is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@encukou @bedevere-bot @vstinner @kumaraditya303
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.