Skip to content

Commit 1270d2c

Browse files
[3.8] bpo-38159: Clarify documentation of PyState_AddModule (GH-16101) (GH-17026)
This was never intented to be called manually from PyInit_*. Also, clarify PyState_RemoveModule return value. (cherry picked from commit 9bc94ec) Co-authored-by: Petr Viktorin <encukou@gmail.com> https://bugs.python.org/issue38159 Automerge-Triggered-By: @encukou
1 parent 0eb6fef commit 1270d2c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Doc/c-api/module.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,21 @@ since multiple such modules can be created from a single definition.
485485
486486
Only effective on modules created using single-phase initialization.
487487
488+
Python calls ``PyState_AddModule`` automatically after importing a module,
489+
so it is unnecessary (but harmless) to call it from module initialization
490+
code. An explicit call is needed only if the module's own init code
491+
subsequently calls ``PyState_FindModule``.
492+
The function is mainly intended for implementing alternative import
493+
mechanisms (either by calling it directly, or by referring to its
494+
implementation for details of the required state updates).
495+
496+
Return 0 on success or -1 on failure.
497+
488498
.. versionadded:: 3.3
489499
490500
.. c:function:: int PyState_RemoveModule(PyModuleDef *def)
491501
492502
Removes the module object created from *def* from the interpreter state.
503+
Return 0 on success or -1 on failure.
493504
494505
.. versionadded:: 3.3

0 commit comments

Comments
 (0)