Repository navigation
gh-162455: Copy the traceback in BaseExceptionGroup.split() and subgroup() even when the original has none - #162464
Open
xgauravyaduvanshii wants to merge 1 commit into
Conversation
… subgroup() even when the original has none When the original group has no traceback, exceptiongroup_subset() skipped copying it, so the parts kept whatever traceback derive() had set. The docs say split() and subgroup() copy __traceback__ from the original group, "so these fields do not need to be updated by derive". The traceback is now always copied; when the original has none, the parts traceback is cleared (Py_None, since SetTraceback rejects NULL). Signed-off-by: Gaurav Kumar Yadav <xgauravyaduvanshii@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #162455.
When the original group has no traceback,
exceptiongroup_subset()skipped copying it, so the parts kept whatever tracebackderive()had set. The docs saysplit()andsubgroup()copy__traceback__(along with__cause__,__context__and__notes__) from the original group, "so these fields do not need to be updated byderive".The fix copies the traceback unconditionally: when the original has none, the parts' traceback is cleared by passing
Py_None(PyException_SetTracebackrejects NULL).Reproduced first with the reporter's example: before the fix it printed
True False False(original has no traceback, both parts do); after the fix it printsTrue True True, andsubgroup()likewise.Tests added in
Lib/test/test_exception_group.py:test_split_and_subgroup_traceback_from_derive_is_replaced— fails without the fix (asserts the parts have no traceback), passes with it.test_split_and_subgroup_copy_traceback— the original traceback is copied to both parts.Verification:
./python -m test test_exception_group test_exceptions test_baseexception— 186 tests run, 3 skipped, all pass.make patchcheckpasses (NEWS entry included).Not verified: no full test-suite run (only the three exception test files), no refleak check.
BaseExceptionGroup.split()andsubgroup()keep the__traceback__thatderive()set when the original group has none #162455