From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 10 Mar 2026 09:32:06 +0000 (+0100) Subject: [3.13] Document that PyType_GetModule returns a borrowed ref (GH-145612) (GH-145732) X-Git-Tag: v3.13.13~115 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f10a1d80f24c7eabf039a106bda8b39a9f8eb3e6;p=thirdparty%2FPython%2Fcpython.git [3.13] Document that PyType_GetModule returns a borrowed ref (GH-145612) (GH-145732) (cherry picked from commit 44855458a423569eaea3df53fd5a0c0032da932d via 30bcdcd379445b942e1278244bbce805dc32b5a2) Co-authored-by: Petr Viktorin --- diff --git a/Doc/c-api/type.rst b/Doc/c-api/type.rst index 84a5b0fc3c0c..1d94718b2d23 100644 --- a/Doc/c-api/type.rst +++ b/Doc/c-api/type.rst @@ -259,6 +259,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 67f551cf6de4..9e0ce81627f2 100644 --- a/Doc/data/refcounts.dat +++ b/Doc/data/refcounts.dat @@ -2398,6 +2398,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::