From dc789275f83d79c96234ba8d1360d2381a406c3b Mon Sep 17 00:00:00 2001 From: Bhuvansh Date: Sat, 3 Oct 2026 21:05:03 +0530 Subject: [PATCH] gh-158643: Document that `Py_EnterRecursiveCall` uses the C stack, not a counter (GH-158644) (cherry picked from commit d6d1ebcdc9f758cff7564dd3aa894c004fc55762) Co-authored-by: Bhuvansh Co-authored-by: An Long --- Doc/c-api/exceptions.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst index 1b9c7ede393f5ca..f9c9e88f74dbad7 100644 --- a/Doc/c-api/exceptions.rst +++ b/Doc/c-api/exceptions.rst @@ -1016,6 +1016,10 @@ because the :ref:`call protocol ` takes care of recursion handling. case, a :exc:`RecursionError` is set and a nonzero value is returned. Otherwise, zero is returned. + The check is based on the remaining C stack space of the current thread, + not on a count of calls, so it is unaffected by + :c:func:`Py_SetRecursionLimit` and :func:`sys.setrecursionlimit`. + *where* should be a UTF-8 encoded string such as ``" in instance check"`` to be concatenated to the :exc:`RecursionError` message caused by the recursion depth limit. @@ -1026,6 +1030,10 @@ because the :ref:`call protocol ` takes care of recursion handling. .. versionchanged:: 3.9 This function is now also available in the :ref:`limited API `. + .. versionchanged:: 3.14 + The check is based on the remaining C stack space. Previously, a + separate counter of C-level calls was used. + .. c:function:: void Py_LeaveRecursiveCall(void) Ends a :c:func:`Py_EnterRecursiveCall`. Must be called once for each