Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

cmaloney
Copy link
Contributor

@cmaloney cmaloney commented Mar 11, 2025

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/

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.
@cmaloney cmaloney changed the title gh-131117: Use PyErr_GetRaisedException in tp_finalize doc gh-131117: Update tp_finalize example to use PyErr_GetRaisedException Mar 12, 2025
: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`,
Copy link
Member

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.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cmaloney
Copy link
Contributor Author

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?

@vstinner
Copy link
Member

I clicked on Update Branch. Let's see if it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting merge docs Documentation in the Doc dir skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

2 participants