| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
…) 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
Documentation build overview153 files changed · + 8 added · ± 145 modified + Added
± Modified |
Sorry, something went wrong.
|
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. |
Sorry, something went wrong.
|
Done, thanks for the suggestions @encukou ! |
Sorry, something went wrong.
|
I'll rebase, and reword a bit. |
Sorry, something went wrong.
Thanks @encukou , this reads much better than what I had! the merge looks good too. should we make the collision case more accurate? in two places (extension-modules.rst from my commits and import.rst in your commit) we're explaining how initfunc is not called again on name collision, but this is technically correct only for builtins and inittab extensions (and modules created through PyImport_CreateModuleFromInitfunc) - those can't collide with .so-file-based extensions (the path is part of the cache key). possible changes:
and for extension-modules.rst: "Modules are matched to the saved contents by the module's full dotted name (and, for extensions loaded from a file, the file's path)". another nit: "reuses the previous module's contents" is only accurate for m_size == -1. For m_size >= 0, the behavior depends on which interpreter loaded the module first (it may re-run the first cached init function, or call the new one). not sure how deeply we want to document that. maybe a short "for modules with m_size of -1" qualifier, or just rely on the "implementation detail" framing. wdyt? happy to push the changes if you'd like. |
Sorry, something went wrong.
|
Hm, right. I guess it makes sense to document this, especially since it's soft-deprecated and thus should not change. I still left out the subinterpreter-specific behaviour, saying it could go either way. Does this look good? Please feel free to push directly, it's your PR :) |
Sorry, something went wrong.
…tfunc-docs-tests
…ommended Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BRMivCCCk5sjAJ6GmBEDUv
|
thanks @encukou, I merged main and pushed a couple of tiny nits, let me know if you have any final feedback before merging! (or just approve if it looks good to you :) ) |
Sorry, something went wrong.
There was a problem hiding this comment.
Looks great! Thank you!
Sorry, something went wrong.
|
GH-159791 is a backport of this pull request to the 3.15 branch. |
Sorry, something went wrong.
…() semantics (GH-157389) (#159791) gh-157384: Document and test PyImport_CreateModuleFromInitfunc() semantics (GH-157389) 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. (cherry picked from commit 0c4ca17) Co-authored-by: Itamar Oren <itamarost@gmail.com> Co-authored-by: Petr Viktorin <encukou@gmail.com>
| Back | FazBrowse Home | New Git URL |
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