-
-
Notifications
You must be signed in to change notification settings - Fork 31.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-131117: Update tp_finalize example to use PyErr_GetRaisedException #131118
base: main
Are you sure you want to change the base?
Conversation
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.
Doc/c-api/typeobj.rst
Outdated
:c:member:`~PyTypeObject.tp_finalize` should not mutate the current exception status; | ||
therefore, a recommended way to write a non-trivial finalizer is:: | ||
:c:member:`~PyTypeObject.tp_finalize` should not mutate the current exception | ||
status. Non-trivial finalizers should use :c:func:`PyErr_GetRaisedException`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"non-trivial" is not accurate. You can have a lot of code which doesn't raise exceptions, and short code which raises exceptions. I prefer to keep the previous sentence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
CI / Github Actions workflow seems to have failed due to some restructuring (https://github.com/python/cpython/actions/runs/13864492893), looks like needs an update branch, should I do that? |
I clicked on Update Branch. Let's see if it helps. |
The
tp_finalize
C API doc currently uses the older PyErr_Fetch + PyErr_Restore API to stash the current exception in its sample implementation. That API was deprecated in 3.12.Update to point to the suggested replacement function PyErr_GetRaisedException which has a sample usage.
📚 Documentation preview 📚: https://cpython-previews--131118.org.readthedocs.build/