-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Unexpected location of naked exception wrapped in except* block #128799
Comments
cc @iritkatriel @1st1 @gvanrossum as the authors of PEP-654. |
I think it's fine to add a frame in the traceback for the |
PR to fix it: #128971 I would call this a bug and backport. @gvanrossum do you agree? |
With the PR:
|
Why does the |
Good catch. It's because the location info for the
|
Bug report
Bug description:
When an
ExceptionGroup
is implicitly constructed by catching a naked exception in anexcept*
block, the traceback of theExceptionGroup
seems to point to the stackframe above where it is logically created:→
I'm not sure if this should be called a bug, as it's not specifically documented how the wrapping ExceptionGroup traceback is constructed. But it is surprising, and did cause a bug in hypothesis where the Exception traceback is used to detect whether an exception originates in hypothesis itself or in user code 12. The issue being that for wrapped naked exceptions we have to inspect the inner exception since the outer exception appears to be raised by the calling function.
As an alternative to the current behaviour, would it be possible to create the wrapper ExceptionGroup with a traceback pointing to where it is logically triggered - i.e., the
except*
block - rather than initially empty? IMO, that would be less suprising and would allow us to use the traceback without special-casing ExceptionGroup.([edit] Or, if the desire is to avoid branching the traceback between the wrapper and the inner exception, use the outermost frame of the naked exception as the initial ExceptionGroup traceback. This would still avoid the appearance of happening in the caller.)
CPython versions tested on:
3.11, 3.12, 3.13
Operating systems tested on:
Linux
Linked PRs
Footnotes
https://github.com/HypothesisWorks/hypothesis/issues/4183 ↩
https://github.com/HypothesisWorks/hypothesis/pull/4239 ↩
The text was updated successfully, but these errors were encountered: