Skip to content

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

Description

@Robertboy18

Bug report

Bug description:

The docs say subgroup() and split() copy the __traceback__, __cause__, __context__ and __notes__ fields from the original group to the one returned by derive(), "so these fields do not need to be updated by derive". When the original group has no traceback, though, the traceback isn't copied, so the result keeps whatever traceback derive() gave it:

class G(ExceptionGroup):
    def derive(self, excs):
        g = G(self.message, excs)
        try:
            raise g
        except G as x:
            return x

g0 = G("m", [ValueError(1), TypeError(2)])
match, rest = g0.split(ValueError)
print(g0.__traceback__ is None, match.__traceback__ is None, rest.__traceback__ is None)

This prints True False False; going by the docs it should print True True True. In exceptiongroup_subset (Objects/exceptions.c) the traceback is only set if (tb), while __context__ and __cause__ are set even when they are None. I found it while writing a Lean spec of Python. PyPy 3.12 prints True True True.

CPython versions tested on:

3.12, 3.15, CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    type-bugAn unexpected behavior, bug, or error
    on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions