gh-103791: Make contextlib.suppress also act on exceptions within an ExceptionGroup#103792
gh-103791: Make contextlib.suppress also act on exceptions within an ExceptionGroup#103792ambv merged 6 commits intopython:mainfrom
Conversation
…in an ExceptionGroup
| match, rest = excinst.split(self._exceptions) | ||
| if rest is None: | ||
| return True | ||
| raise rest |
There was a problem hiding this comment.
This isn't ideal as it makes the exception group's own traceback include the def __exit__(...) frame. For example:
File "/Volumes/RAMDisk/cpython/Lib/test/test_contextlib.py", line 1220, in test_exception_groups
with suppress(ValueError):
File "/Volumes/RAMDisk/cpython/Lib/contextlib.py", line 454, in __exit__
raise rest from excinst
File "/Volumes/RAMDisk/cpython/Lib/test/test_contextlib.py", line 1221, in test_exception_groups
raise eg_all()
in case of the newly added test.
This isn't a big problem because:
- the group's member exceptions contain pristine tracebacks, only the group itself contains extra frames; and
- the
raiseof the original group is still included in the traceback because we used.split()to create the new object.
Ideally, we wouldn't need this. However, the API of __exit__ makes it impossible to replace the ExceptionGroup instance with another one, while ExceptionGroup itself makes its exceptions read-only.
Misc/NEWS.d/next/Library/2023-04-24-23-07-56.gh-issue-103791.bBPWdS.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: Irit Katriel <[email protected]>
hugovk
left a comment
There was a problem hiding this comment.
(just testing out "request changes")
|
When you're done making the requested changes, leave the comment: |
OK, GitHub indeed doesn't disable auto-merge when changes are requested
* main: pythongh-87729: add LOAD_SUPER_ATTR instruction for faster super() (python#103497) pythongh-103791: Make contextlib.suppress also act on exceptions within an ExceptionGroup (python#103792)
| return | ||
| if issubclass(exctype, self._exceptions): | ||
| return True | ||
| if issubclass(exctype, ExceptionGroup): |
There was a problem hiding this comment.
Was there a specific reason to handle ExceptionGroup but not BaseExceptionGroup?
There was a problem hiding this comment.
I doubt it. Want to make a PR?
Uh oh!
There was an error while loading. Please reload this page.