From 280cead3f4cc4bc294edc04a69c911464e14abbe Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Mon, 9 Mar 2026 14:32:28 +0100 Subject: [PATCH] [3.14] Document that PyType_GetModule returns a borrowed ref (GH-145612) (cherry picked from commit 44855458a423569eaea3df53fd5a0c0032da932d) Co-authored-by: Petr Viktorin --- Doc/c-api/type.rst | 4 ++++ Doc/data/refcounts.dat | 3 +++ 2 files changed, 7 insertions(+) diff --git a/Doc/c-api/type.rst b/Doc/c-api/type.rst index 2f2060d0582251..7fe810f585fa35 100644 --- a/Doc/c-api/type.rst +++ b/Doc/c-api/type.rst @@ -274,6 +274,10 @@ Type Objects Return the module object associated with the given type when the type was created using :c:func:`PyType_FromModuleAndSpec`. + The returned reference is :term:`borrowed ` from *type*, + and will be valid as long as you hold a reference to *type*. + Do not release it with :c:func:`Py_DECREF` or similar. + If no module is associated with the given type, sets :py:class:`TypeError` and returns ``NULL``. diff --git a/Doc/data/refcounts.dat b/Doc/data/refcounts.dat index 1cc1b44a5b8e3a..48b800fdf9a533 100644 --- a/Doc/data/refcounts.dat +++ b/Doc/data/refcounts.dat @@ -2415,6 +2415,9 @@ PyType_GetFlags:PyTypeObject*:type:0: PyType_GetName:PyObject*::+1: PyType_GetName:PyTypeObject*:type:0: +PyType_GetModule:PyObject*::0: +PyType_GetModule:PyTypeObject*:type:0: + PyType_GetModuleByDef:PyObject*::0: PyType_GetModuleByDef:PyTypeObject*:type:0: PyType_GetModuleByDef:PyModuleDef*:def::