From: Cody Maloney Date: Wed, 19 Mar 2025 17:27:55 +0000 (-0700) Subject: gh-131117: Update tp_finalize example to use PyErr_GetRaisedException (#131118) X-Git-Tag: v3.14.0a7~301 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a4832f6b9a62771725b159bc7cd6c49fb45e3bc8;p=thirdparty%2FPython%2Fcpython.git 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. --- diff --git a/Doc/c-api/typeobj.rst b/Doc/c-api/typeobj.rst index c5229d19ca0a..51c9f05fd6a8 100644 --- a/Doc/c-api/typeobj.rst +++ b/Doc/c-api/typeobj.rst @@ -2154,15 +2154,13 @@ and :c:data:`PyType_Type` effectively act as defaults.) static void local_finalize(PyObject *self) { - PyObject *error_type, *error_value, *error_traceback; - /* Save the current exception, if any. */ - PyErr_Fetch(&error_type, &error_value, &error_traceback); + PyObject *exc = PyErr_GetRaisedException(); /* ... */ /* Restore the saved exception. */ - PyErr_Restore(error_type, error_value, error_traceback); + PyErr_SetRaisedException(exc); } **Inheritance:**