From 26c95c085bf4cebaab4954aa1c41faffce6ebda6 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Sat, 22 Nov 2025 10:42:31 -0500 Subject: [PATCH 1/4] Document PyImport_Inittab --- Doc/c-api/import.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Doc/c-api/import.rst b/Doc/c-api/import.rst index 971c6a69e5d065..e1c1f824ca4911 100644 --- a/Doc/c-api/import.rst +++ b/Doc/c-api/import.rst @@ -314,6 +314,13 @@ Importing Modules initialization. +.. c:var:: struct _inittab *PyImport_Inittab + + The table of built-in modules used by Python. Do not use this directly; use + :c:func:`PyImport_ExtendInittab` and :c:func:`PyImport_AppendInittab` + instead. + + .. c:function:: PyObject* PyImport_ImportModuleAttr(PyObject *mod_name, PyObject *attr_name) Import the module *mod_name* and get its attribute *attr_name*. From 2ae380e959887fbab9d1be93356f358a39b4fdd4 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Sat, 22 Nov 2025 15:52:37 +0000 Subject: [PATCH 2/4] Commit --- Doc/extending/extending.rst | 2 +- Misc/NEWS.d/3.11.0a1.rst | 2 +- Misc/NEWS.d/3.12.0a2.rst | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/extending/extending.rst b/Doc/extending/extending.rst index dee92312169a27..f9b65643dfe888 100644 --- a/Doc/extending/extending.rst +++ b/Doc/extending/extending.rst @@ -426,7 +426,7 @@ A pointer to the module definition must be returned via :c:func:`PyModuleDef_Ini so that the import machinery can create the module and store it in ``sys.modules``. When embedding Python, the :c:func:`!PyInit_spam` function is not called -automatically unless there's an entry in the :c:data:`!PyImport_Inittab` table. +automatically unless there's an entry in the :c:data:`PyImport_Inittab` table. To add the module to the initialization table, use :c:func:`PyImport_AppendInittab`, optionally followed by an import of the module:: diff --git a/Misc/NEWS.d/3.11.0a1.rst b/Misc/NEWS.d/3.11.0a1.rst index c7e57754ee3341..10ef2968db2684 100644 --- a/Misc/NEWS.d/3.11.0a1.rst +++ b/Misc/NEWS.d/3.11.0a1.rst @@ -4931,7 +4931,7 @@ Patch by Gabriele N. Tornetta .. nonce: 3p14JB .. section: C API -:c:func:`Py_RunMain` now resets :c:data:`!PyImport_Inittab` to its initial +:c:func:`Py_RunMain` now resets :c:data:`PyImport_Inittab` to its initial value at exit. It must be possible to call :c:func:`PyImport_AppendInittab` or :c:func:`PyImport_ExtendInittab` at each Python initialization. Patch by Victor Stinner. diff --git a/Misc/NEWS.d/3.12.0a2.rst b/Misc/NEWS.d/3.12.0a2.rst index bc028f30636bf7..20e27c0d92f05f 100644 --- a/Misc/NEWS.d/3.12.0a2.rst +++ b/Misc/NEWS.d/3.12.0a2.rst @@ -35,11 +35,11 @@ Update bundled libexpat to 2.5.0 .. nonce: ik4iOv .. section: Core and Builtins -The docs clearly say that ``PyImport_Inittab``, +The docs clearly say that :c:data:`PyImport_Inittab`, :c:func:`PyImport_AppendInittab`, and :c:func:`PyImport_ExtendInittab` should not be used after :c:func:`Py_Initialize` has been called. We now enforce this for the two functions. Additionally, the runtime now uses an -internal copy of ``PyImport_Inittab``, to guard against modification. +internal copy of :c:data:`PyImport_Inittab`, to guard against modification. .. From ee2dcac381a7a7b21809be259762cee60dede9e2 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Sat, 22 Nov 2025 11:14:26 -0500 Subject: [PATCH 3/4] Update Doc/c-api/import.rst --- Doc/c-api/import.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/c-api/import.rst b/Doc/c-api/import.rst index e1c1f824ca4911..159e4e159e92b0 100644 --- a/Doc/c-api/import.rst +++ b/Doc/c-api/import.rst @@ -316,8 +316,8 @@ Importing Modules .. c:var:: struct _inittab *PyImport_Inittab - The table of built-in modules used by Python. Do not use this directly; use - :c:func:`PyImport_ExtendInittab` and :c:func:`PyImport_AppendInittab` + The table of built-in modules used by Python initialization. Do not use this directly; + use :c:func:`PyImport_ExtendInittab` and :c:func:`PyImport_AppendInittab` instead. From 30bc696b1ee414b035b8a33c874c71934f3573c7 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Mon, 24 Nov 2025 11:32:37 -0500 Subject: [PATCH 4/4] Update Doc/c-api/import.rst Co-authored-by: Victor Stinner --- Doc/c-api/import.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/c-api/import.rst b/Doc/c-api/import.rst index 159e4e159e92b0..ca2e575bcc017a 100644 --- a/Doc/c-api/import.rst +++ b/Doc/c-api/import.rst @@ -317,7 +317,7 @@ Importing Modules .. c:var:: struct _inittab *PyImport_Inittab The table of built-in modules used by Python initialization. Do not use this directly; - use :c:func:`PyImport_ExtendInittab` and :c:func:`PyImport_AppendInittab` + use :c:func:`PyImport_AppendInittab` and :c:func:`PyImport_ExtendInittab` instead.