From 5ba3e9308be189e11b682b08310f0ce0828bda61 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Fri, 7 Nov 2025 08:27:45 -0500 Subject: [PATCH 1/3] Document traceback object APIs. --- Doc/c-api/exceptions.rst | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst index 9c75f66f683195..81c66860847f35 100644 --- a/Doc/c-api/exceptions.rst +++ b/Doc/c-api/exceptions.rst @@ -1228,3 +1228,36 @@ Warning types .. versionadded:: 3.10 :c:data:`PyExc_EncodingWarning`. + +Tracebacks +========== + +.. c:var:: PyTypeObject PyTraceBack_Type + + Type object for traceback objects. This is available as + :class:`types.TracebackType` in the Python layer. + + +.. c:function:: int PyTraceBack_Check(PyObject *op) + + Return true if *op* is a traceback object, false otherwise. This function + does not account for subtypes. + + +.. c:function:: int PyTraceBack_Here(PyFrameObject *f) + + Replace the :attr:`~BaseException.__traceback__` attribute on the current + exception with a new traceback pointing to *f*. + + Calling this function without an exception set is undefined behavior. + + This function returns ``0`` on success, and returns ``-1`` with an + exception set on failure. + + +.. c:function:: int PyTraceBack_Print(PyObject *tb, PyObject *f) + + Write the traceback *tb* into the file *f*. + + This function returns ``0`` on success, and returns ``-1`` with an + exception set on failure. From d4d3ac166d05026a1c04835a2620049c3292ff20 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Fri, 7 Nov 2025 11:15:15 -0500 Subject: [PATCH 2/3] Update Doc/c-api/exceptions.rst Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- Doc/c-api/exceptions.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst index 81c66860847f35..447f5e06f2a2fe 100644 --- a/Doc/c-api/exceptions.rst +++ b/Doc/c-api/exceptions.rst @@ -1229,6 +1229,7 @@ Warning types .. versionadded:: 3.10 :c:data:`PyExc_EncodingWarning`. + Tracebacks ========== From f2eb89d7292178bb27ee30bba2b2cbd4954c4e17 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Fri, 7 Nov 2025 13:28:55 -0500 Subject: [PATCH 3/3] Update exceptions.rst Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- Doc/c-api/exceptions.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst index 447f5e06f2a2fe..77ede933de4e85 100644 --- a/Doc/c-api/exceptions.rst +++ b/Doc/c-api/exceptions.rst @@ -1248,7 +1248,7 @@ Tracebacks .. c:function:: int PyTraceBack_Here(PyFrameObject *f) Replace the :attr:`~BaseException.__traceback__` attribute on the current - exception with a new traceback pointing to *f*. + exception with a new traceback prepending *f* to the existing chain. Calling this function without an exception set is undefined behavior.