Skip to content

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
python:mainfrom
xgauravyaduvanshii:fix/exceptiongroup-split-traceback-162455
Open

xgauravyaduvanshii wants to merge 1 commit into
python:mainfrom
xgauravyaduvanshii:fix/exceptiongroup-split-traceback-162455

Conversation

@xgauravyaduvanshii

@xgauravyaduvanshii xgauravyaduvanshii commented Nov 22, 2026 •

Copy link
Copy Markdown

Fixes #162455.

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__ (along with __cause__, __context__ and __notes__) from the original group, "so these fields do not need to be updated by derive".

The fix copies the traceback unconditionally: when the original has none, the parts' traceback is cleared by passing Py_None (PyException_SetTraceback rejects 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 prints True True True, and subgroup() 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 patchcheck passes (NEWS entry included).

Not verified: no full test-suite run (only the three exception test files), no refleak check.

… 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BaseExceptionGroup.split() and subgroup() keep the __traceback__ that derive() set when the original group has none

1 participant