Skip to content

Commit 69db2eb

Browse files
[3.13] gh-131117: Update tp_finalize example to use PyErr_GetRaisedException (GH-131118) (#131476)
gh-131117: Update tp_finalize example to use PyErr_GetRaisedException (GH-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. (cherry picked from commit a4832f6) Co-authored-by: Cody Maloney <[email protected]>
1 parent 1222722 commit 69db2eb

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

Doc/c-api/typeobj.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,15 +2153,13 @@ and :c:data:`PyType_Type` effectively act as defaults.)
21532153
static void
21542154
local_finalize(PyObject *self)
21552155
{
2156-
PyObject *error_type, *error_value, *error_traceback;
2157-
21582156
/* Save the current exception, if any. */
2159-
PyErr_Fetch(&error_type, &error_value, &error_traceback);
2157+
PyObject *exc = PyErr_GetRaisedException();
21602158

21612159
/* ... */
21622160

21632161
/* Restore the saved exception. */
2164-
PyErr_Restore(error_type, error_value, error_traceback);
2162+
PyErr_SetRaisedException(exc);
21652163
}
21662164

21672165
**Inheritance:**

0 commit comments

Comments
 (0)