https://github.com/python/cpython/commit/69db2ebfce88f30275b3cd392661f4611836c315
commit: 69db2ebfce88f30275b3cd392661f4611836c315
branch: 3.13
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: vstinner <vstin...@python.org>
date: 2025-03-19T17:34:15Z
summary:

[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 a4832f6b9a62771725b159bc7cd6c49fb45e3bc8)

Co-authored-by: Cody Maloney <cmalo...@users.noreply.github.com>

files:
M Doc/c-api/typeobj.rst

diff --git a/Doc/c-api/typeobj.rst b/Doc/c-api/typeobj.rst
index 191f3690bccd5c..f74294a0fd7e16 100644
--- a/Doc/c-api/typeobj.rst
+++ b/Doc/c-api/typeobj.rst
@@ -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:**

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to