Skip to content

gh-157384: Document and test PyImport_CreateModuleFromInitfunc() semantics - #157389

Open
itamaro wants to merge 2 commits into
python:mainfrom
itamaro:gh-116146-initfunc-docs-tests
Open

itamaro wants to merge 2 commits into
python:mainfrom
itamaro:gh-116146-initfunc-docs-tests

Conversation

@itamaro

@itamaro itamaro commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Document that single-phase init modules are added to sys.modules by the call itself (unlike multi-phase init modules), and that the spec name identifies the module, so a later call with the same name and a different init function reuses the cached module without calling the new init function. Add regression tests for both behaviors.

AI assisted with Claude Fable 5.1

…) semantics

Document that single-phase init modules are added to sys.modules by
the call itself (unlike multi-phase init modules), and that the spec
name identifies the module, so a later call with the same name and a
different init function reuses the cached module without calling the
new init function.  Add regression tests for both behaviors.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HoZE3WdRWQshvinfBZ137N
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34530624 | 📁 Comparing 16b70db against main (2cd6d4b)

  🔍 Preview build  

1 file changed
± c-api/import.html

@encukou

encukou commented Sep 14, 2026

Copy link
Copy Markdown
Member

Could you turn “legacy single-phase initialization” into a link? (And remove the parenthesis -- PyModule_Create is just an example.)

Also, please link the “as is done for”/“as for” parts -- the docs for the mentioned feature should explain what happens in more detail; if they don't then the mention isn't very useful.

The existing docs already point out that the init function is not called twice. It would be nice to clarify there what the “lookup key“ is when determining subsequent imports of the “same” module.

Comment thread Doc/c-api/import.rst Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review needs backport to 3.15 pre-release feature fixes, bugs and security fixes skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants