From 6d4ad50e12afdebf645889de6db3cbbe9e794da1 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Wed, 25 Jun 2025 08:56:21 -0400 Subject: [PATCH 1/2] Document PyFunction_GET_BUILTINS --- Doc/c-api/function.rst | 8 ++++++++ Doc/data/refcounts.dat | 3 +++ 2 files changed, 11 insertions(+) diff --git a/Doc/c-api/function.rst b/Doc/c-api/function.rst index 5fb8567ef8c95f..b33ac5054b6332 100644 --- a/Doc/c-api/function.rst +++ b/Doc/c-api/function.rst @@ -142,6 +142,14 @@ There are a few functions specific to Python functions. do not do type checking. Passing anything other than an instance of :c:data:`PyFunction_Type` is undefined behavior. +.. c:function:: PyObject *PyFunction_GET_BUILTINS(PyObject *op) + + Return the dictionary used to look up builtins when calling function *op*. + + This function does not do error checking; passing anything other than an + instance of :c:data:`PyFunction_Type` is undefined behavior. + + .. versionadded 3.14 .. c:function:: int PyFunction_AddWatcher(PyFunction_WatchCallback callback) diff --git a/Doc/data/refcounts.dat b/Doc/data/refcounts.dat index 144c5608e07426..5072db7da1c932 100644 --- a/Doc/data/refcounts.dat +++ b/Doc/data/refcounts.dat @@ -966,6 +966,9 @@ PyFunction_GetAnnotations:PyObject*:op:0: PyFunction_GET_ANNOTATIONS:PyObject*::0: PyFunction_GET_ANNOTATIONS:PyObject*:op:0: +PyFunction_GET_BUILTINS:PyObject*::0: +PyFunction_GET_BUILTINS:PyObject*:op:0: + PyFunction_GetClosure:PyObject*::0: PyFunction_GetClosure:PyObject*:op:0: From 58f7229c4a024d270cd7f7d2c83f4f17bb4a5052 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Wed, 25 Jun 2025 09:00:37 -0400 Subject: [PATCH 2/2] Add some clarification. --- Doc/c-api/function.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Doc/c-api/function.rst b/Doc/c-api/function.rst index b33ac5054b6332..7d709820f65566 100644 --- a/Doc/c-api/function.rst +++ b/Doc/c-api/function.rst @@ -144,10 +144,12 @@ There are a few functions specific to Python functions. .. c:function:: PyObject *PyFunction_GET_BUILTINS(PyObject *op) - Return the dictionary used to look up builtins when calling function *op*. + Return the dictionary used to look up builtins (which might be ``NULL``) + when calling function *op*. - This function does not do error checking; passing anything other than an - instance of :c:data:`PyFunction_Type` is undefined behavior. + This function cannot fail and does not do error checking; passing anything + other than an instance of :c:data:`PyFunction_Type` is undefined behavior. + There is no ``PyFunction_Get*`` equivalent for this function. .. versionadded 3.14