-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-90501: Add PyErr_GetHandledException and PyErr_SetHandledException #30531
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-90501: Add PyErr_GetHandledException and PyErr_SetHandledException #30531
Conversation
a562251
to
e76ac6a
Compare
3fce147
to
20fa421
Compare
Co-authored-by: Victor Stinner <[email protected]>
Co-authored-by: Kumar Aditya <[email protected]>
Co-authored-by: Kumar Aditya <[email protected]>
Cython defines |
Is it clear (judging by name only) which exception is the "active" one? Raised/in-flight or caught? :) |
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.
Since this function is an unusal use case, maybe give it an even more explicit name? PyErr_GetCaughtException()?
Would it be possible to use the same wording in the documentation of functions added by this PR, in PyErr_GetExcInfo() and in sys.exception() documentation? My remark is about "the exception instance that is currently being handled" in sys.exception() doc: Maybe add also a link from PyErr_GetExcInfo() to PyErr_GetActiveException() in the doc. |
Co-authored-by: Victor Stinner <[email protected]>
How about GetHandledException()? (I'm not sure Caught accurately describes the timeframe in which an exception is "active"). |
sys.exception is in python space, where you don't have access to any other exception so I think the c-level wording might just add confusion. I agree though that the current wording is not great, in particular I'm not sure we need to talk about the frame stack. How about I reword the sys.exception() doc like this:
Sure. |
…leak in test_set_exception. Use METH_O in test_set_exception
I made all the changes suggested in reviews so far (thanks!) except the name change. I propose SetHandledException/GetHandledException. Does this sound good? |
IMO , that's easier to understand. +1 |
@vstinner @encukou @markshannon Any last thoughts on this? Should we include this in 3.11? @pablogsal FYI. |
1 similar comment
@vstinner @encukou @markshannon Any last thoughts on this? Should we include this in 3.11? @pablogsal FYI. |
I'm fine including this into 3.11, but please merge it at least one week before the beta to allow to test it a bit. |
Now that exc_info was replace by just the exception, we can have simpler versions of the get/set c-api functions.
https://bugs.python.org/issue46343