]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-131117: Update tp_finalize example to use PyErr_GetRaisedException (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 19 Mar 2025 17:34:15 +0000 (18:34 +0100)
committerGitHub <noreply@github.com>
Wed, 19 Mar 2025 17:34:15 +0000 (17:34 +0000)
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 a4832f6b9a62771725b159bc7cd6c49fb45e3bc8)

Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
Doc/c-api/typeobj.rst

index 191f3690bccd5c9a2a03a4eb6d69dd83caa02ee8..f74294a0fd7e167091d509271eacb4081c710667 100644 (file)
@@ -2153,15 +2153,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:**