From 608c3ebc10c89a5c13ad9cb8856fd4477e4458f4 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Thu, 19 Jun 2025 09:00:41 +0200 Subject: [PATCH] Document that PyType_GetModuleByDef returns a borrowed reference (GH-135666) (cherry picked from commit 140731ff671395fb7a869c2784429c14dc83fb27) Co-authored-by: Petr Viktorin --- Doc/c-api/type.rst | 4 ++++ Doc/data/refcounts.dat | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Doc/c-api/type.rst b/Doc/c-api/type.rst index 2176b8e492f306..5bdbff4e0ad990 100644 --- a/Doc/c-api/type.rst +++ b/Doc/c-api/type.rst @@ -282,6 +282,10 @@ Type Objects and other places where a method's defining class cannot be passed using the :c:type:`PyCMethod` calling convention. + 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. + .. versionadded:: 3.11 .. c:function:: int PyType_GetBaseByToken(PyTypeObject *type, void *token, PyTypeObject **result) diff --git a/Doc/data/refcounts.dat b/Doc/data/refcounts.dat index 29f430d4786248..7db5ec6712c4ed 100644 --- a/Doc/data/refcounts.dat +++ b/Doc/data/refcounts.dat @@ -2388,6 +2388,10 @@ PyType_GetFlags:PyTypeObject*:type:0: PyType_GetName:PyObject*::+1: PyType_GetName:PyTypeObject*:type:0: +PyType_GetModuleByDef:PyObject*::0: +PyType_GetModuleByDef:PyTypeObject*:type:0: +PyType_GetModuleByDef:PyModuleDef*:def:: + PyType_GetQualName:PyObject*::+1: PyType_GetQualName:PyTypeObject*:type:0: