Skip to content

Commit 1f53dc3

Browse files
committed
gh-131117: Use PyErr_GetRaisedException in tp_finalize doc
The tp_finalize C API doc used PyErr_Fetch and PyErr_Restore in its example code. That API was deprecated in 3.12. Update to point to the suggested replacement function PyErr_GetRaisedException which has a sample usage.
1 parent ad90c5f commit 1f53dc3

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

Doc/c-api/typeobj.rst

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,21 +2149,8 @@ and :c:data:`PyType_Type` effectively act as defaults.)
21492149
that it finds the object in a sane state.
21502150

21512151
:c:member:`~PyTypeObject.tp_finalize` should not mutate the current exception status;
2152-
therefore, a recommended way to write a non-trivial finalizer is::
2153-
2154-
static void
2155-
local_finalize(PyObject *self)
2156-
{
2157-
PyObject *error_type, *error_value, *error_traceback;
2158-
2159-
/* Save the current exception, if any. */
2160-
PyErr_Fetch(&error_type, &error_value, &error_traceback);
2161-
2162-
/* ... */
2163-
2164-
/* Restore the saved exception. */
2165-
PyErr_Restore(error_type, error_value, error_traceback);
2166-
}
2152+
therefore, a recommended way to write a non-trivial finalizer is with
2153+
:c:func:`PyErr_GetRaisedException`
21672154

21682155
**Inheritance:**
21692156

0 commit comments

Comments
 (0)