Skip to content

Commit a4832f6

Browse files
authored
gh-131117: Update tp_finalize example to use PyErr_GetRaisedException (#131118)
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 5c44d7d commit a4832f6

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

Doc/c-api/typeobj.rst

+2-4
Original file line numberDiff line numberDiff line change
@@ -2154,15 +2154,13 @@ and :c:data:`PyType_Type` effectively act as defaults.)
21542154
static void
21552155
local_finalize(PyObject *self)
21562156
{
2157-
PyObject *error_type, *error_value, *error_traceback;
2158-
21592157
/* Save the current exception, if any. */
2160-
PyErr_Fetch(&error_type, &error_value, &error_traceback);
2158+
PyObject *exc = PyErr_GetRaisedException();
21612159

21622160
/* ... */
21632161

21642162
/* Restore the saved exception. */
2165-
PyErr_Restore(error_type, error_value, error_traceback);
2163+
PyErr_SetRaisedException(exc);
21662164
}
21672165

21682166
**Inheritance:**

0 commit comments

Comments
 (0)