Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

iritkatriel
Copy link
Member

@iritkatrieliritkatriel commentedJan 11, 2022
edited
Loading

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

@iritkatrieliritkatrielforce-pushed thebpo-46343-GetSetException branch from3fce147 to20fa421CompareJanuary 13, 2022 14:21
@iritkatrieliritkatriel requested a review froma team as acode ownerJanuary 13, 2022 14:21
Co-authored-by: Victor Stinner <vstinner@python.org>
iritkatrieland others added2 commitsJanuary 17, 2022 13:32
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
@vstinner
Copy link
Member

Cython defines__Pyx_PyErr_GetTopmostException() inCython/Utility/Exceptions.c which is a copy of PythonPyErr_GetTopmostException(). It seems like Cython cannot usePyErr_GetActiveException() but would need a function taking atstate parameter.

@erlend-aasland
Copy link
Contributor

In python you can only access this exception, so it'ssys.exception() but in the C api there are two exceptions we can access - the in-flight (raised) exception or this (caught) exception. So I think we need to be clear which one this is.

Is it clear (judging by name only) which exception is the "active" one? Raised/in-flight or caught? :)

Copy link
Member

@vstinnervstinner left a 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()?

@vstinner
Copy link
Member

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:
https://docs.python.org/dev/library/sys.html#sys.exception

Maybe add also a link from PyErr_GetExcInfo() to PyErr_GetActiveException() in the doc.

Co-authored-by: Victor Stinner <vstinner@python.org>
@iritkatriel
Copy link
MemberAuthor

Since this function is an unusal use case, maybe give it an even more explicit name? PyErr_GetCaughtException()?

How about GetHandledException()?

(I'm not sure Caught accurately describes the timeframe in which an exception is "active").

@iritkatriel
Copy link
MemberAuthor

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:https://docs.python.org/dev/library/sys.html#sys.exception

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:

This function, when called while an exception handler (such as an ``except`` or ``except*`` clause) is executing, returns the exception instance that was caught by this handler. When exception handlers are nested within one another, only the exception handled by the innermost handler is accessible.If no exception handler is executing, this function returns None.

Maybe add also a link from PyErr_GetExcInfo() to PyErr_GetActiveException() in the doc.

Sure.

iritkatriel reacted with thumbs up emoji

@iritkatriel
Copy link
MemberAuthor

I made all the changes suggested in reviews so far (thanks!) except the name change.

I propose SetHandledException/GetHandledException. Does this sound good?

@iritkatrieliritkatriel changed the titlebpo-46343: Add PyErr_GetActiveException and PyErr_SetActiveExceptionbpo-46343: Add PyErr_GetHandledException and PyErr_SetHandledExceptionApr 13, 2022
@iritkatrieliritkatriel changed the titlebpo-46343: Add PyErr_GetHandledException and PyErr_SetHandledExceptiongh-90501: Add PyErr_GetHandledException and PyErr_SetHandledExceptionApr 13, 2022
@erlend-aasland
Copy link
Contributor

I propose SetHandledException/GetHandledException. Does this sound good?

IMO , that's easier to understand. +1

@iritkatriel
Copy link
MemberAuthor

@vstinner@encukou@markshannon Any last thoughts on this? Should we include this in 3.11?

@pablogsal FYI.

1 similar comment
@iritkatriel
Copy link
MemberAuthor

@vstinner@encukou@markshannon Any last thoughts on this? Should we include this in 3.11?

@pablogsal FYI.

@pablogsal
Copy link
Member

@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.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@vstinnervstinnervstinner left review comments

@kumaraditya303kumaraditya303kumaraditya303 left review comments

@encukouencukouAwaiting requested review from encukou

@markshannonmarkshannonAwaiting requested review from markshannon

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

8 participants
@iritkatriel@vstinner@markshannon@erlend-aasland@pablogsal@kumaraditya303@the-knights-who-say-ni@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp