mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
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.
This commit is contained in:
parent
5c44d7d99c
commit
a4832f6b9a
1 changed files with 2 additions and 4 deletions
|
@ -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:**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue