FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-116146: Add C-API to create module from spec and initfunc by itamaro · Pull Request #139196 · python/cpython · GitHub

/ cpython Public

gh-116146: Add C-API to create module from spec and initfunc - #139196

Merged
encukou merged 15 commits into
python:mainfrom
itamaro:gh-116146-create-builtin-initfunc
Nov 14, 2025
Merged

gh-116146: Add C-API to create module from spec and initfunc#139196
encukou merged 15 commits into
python:mainfrom
itamaro:gh-116146-create-builtin-initfunc

Conversation

itamaro commented Sep 21, 2025
edited
Loading

Copy link
Copy Markdown
Contributor

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This looks reasonable.

I'm proposing a replacement for Init functions in PEP-793, but that PEP adds PyModule_FromSlotsAndSpec and PyModule_Exec which should work for similar use cases.
Would it make sense to switch the spec & initfunc arguments to match that proposal?

I'm not sure if the word Builtin in the name is necessary -- is that to match the internal create_builtin? Would something like PyImport_LoadModuleFromInitfuncAndSpec work better?

Do you want to submit this to the C API WG?

Comment thread Python/import.c Outdated

itamaro commented Sep 23, 2025

Copy link
Copy Markdown
Contributor Author

Would it make sense to switch the spec & initfunc arguments to match that proposal?

I think it should be fine! Is the PEP already implemented on main?

I'm not sure if the word Builtin in the name is necessary -- is that to match the internal create_builtin? Would something like PyImport_LoadModuleFromInitfuncAndSpec work better?

Yes, I used it to reflect what it does internally. PyImport_LoadModuleFromInitfuncAndSpec sounds great to me!

Do you want to submit this to the C API WG?

Will do. Should we first decide whether to change this to match PEP 793, or go to the WP with options and get their input?

encukou commented Sep 24, 2025

Copy link
Copy Markdown
Member

Is the PEP already implemented on main?

No, it's not even accepted :)
I have a slight preference to align the two proposals, in case both make it. I'm checking if you have strong reasons for the order here. No need to update the PR now.

Will do. Should we first decide whether to change this to match PEP 793, or go to the WP with options and get their input?

Just go to the WG :)

itamaro commented Sep 24, 2025

Copy link
Copy Markdown
Contributor Author

Just go to the WG :)

done :) capi-workgroup/decisions#77

Comment thread Python/import.c Outdated
itamaro force-pushed the gh-116146-create-builtin-initfunc branch from 4363e5a to 781a730 Compare November 8, 2025 18:52
- remove unused `found` variable
- use `my_test_extension` instead of `embedded_ext` (the former is free-threading-ready, the latter prints a warning)
itamaro changed the title gh-116146: Add new C-API to create builtin from spec and initfunc gh-116146: Add C-API to create module from spec and initfunc Nov 9, 2025
itamaro marked this pull request as ready for review November 9, 2025 01:01
Comment thread Python/import.c Outdated
Co-authored-by: Kumar Aditya <kumaraditya@python.org>

encukou commented Nov 11, 2025

Copy link
Copy Markdown
Member

I left my suggestions as a PR: itamaro#27

* Test single-phase init as well; don't use private APIs in test
* Doc update

---------

Co-authored-by: Itamar Oren <itamarost@gmail.com>
Comment thread Doc/c-api/import.rst Outdated
Comment thread Include/cpython/import.h Outdated
Comment thread Programs/_testembed.c Outdated
Comment thread Programs/_testembed.c Outdated
Comment thread Programs/_testembed.c Outdated
Comment thread Python/import.c
Co-authored-by: Victor Stinner <vstinner@python.org>

python-cla-bot Bot commented Nov 12, 2025
edited
Loading

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

itamaro force-pushed the gh-116146-create-builtin-initfunc branch from 8f16533 to 1165950 Compare November 12, 2025 16:18

itamaro commented Nov 12, 2025

Copy link
Copy Markdown
Contributor Author

thank you @encukou @vstinner @kumaraditya303 for the review and suggestions!

@encukou are you planning to merge gh-141197 soon? until that is merged, this PR has a docs failure due to referring to the function that you document in gh-141197.

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The new function PyImport_CreateModuleFromInitfunc() should be documented in Doc/whatsnew/3.15.rst.

Comment thread Doc/c-api/import.rst Outdated
Comment thread Include/cpython/import.h Outdated
Comment thread Programs/_testembed.c Outdated
Comment thread Python/import.c Outdated
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Victor Stinner <vstinner@python.org>
itamaro requested a review from AA-Turner as a code owner November 13, 2025 15:31
itamaro force-pushed the gh-116146-create-builtin-initfunc branch from fabafb5 to fbfde0a Compare November 13, 2025 15:32

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM. Thanks for the updates!

encukou merged commit 1e4e59b into python:main Nov 14, 2025
46 checks passed
encukou added a commit to encukou/cpython that referenced this pull request Nov 14, 2025

Copy link
Copy Markdown
Member

Congrats @itamaro!

itamaro deleted the gh-116146-create-builtin-initfunc branch November 15, 2025 23:40
StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
…ythonGH-139196)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

4 participants


Back | FazBrowse Home | New Git URL