Repository navigation
ExceptionGroup repr is misleading if original exception sequence is mutated #141732
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Nov 19, 2025 I noticed that PyPy behaves the way I expected here; they use
self.exceptionsinBaseExceptionGroup.__repr__instead ofself.args[1]:On CPython, it looks like
BaseExceptionGroup.__repr__resolves toBaseException.__repr__, so the repr ends up usingself.args[1]instead ofself.exceptions.I skimmed the PEP and didn't see anything that indicated that either repr implementation is in violation of the PEP.
Reacted by dr-carlosI skimmed the PEP and didn't see anything that indicated that either repr implementation is in violation of the PEP.
The PEP does reference the
repr()ofExceptionGroups but not explicitly specify anything:>>> try: ... raise ExceptionGroup("problem", [BlockingIOError()]) ... except* OSError as e: # Would catch the error ... print(repr(e)) ... except* BlockingIOError: # Would never run ... print('never') ... ExceptionGroup('problem', [BlockingIOError()])
But I agree that mutating an argument which is only used to create an immutable tuple shouldn't change the repr.
Reacted by Ganden SchaffnerThis may be a part of more complex problem. See #137889.
Reacted by dr-carlos and Ganden Schaffner- addedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
on Nov 19, 2025 - added a commit that references this issue
on Dec 7, 2025 - added a commit that references this issue
on Dec 8, 2025 This has been merged in
mainand 3.13 but cannot be merged for 3.14 because of failing CI: #142388.Please can you check the backport?
- added a commit that references this issue
on Feb 8, 2026 - added a commit that references this issue
on Feb 14, 2026 - added a commit that references this issue
on Feb 25, 2026 - added a commit that references this issue
on Mar 23, 2026
Bug report
Bug description:
The exception listing in
repr(exc_grp)diverges fromexc_grp.exceptionswhen the initial sequence of exceptions passed to the constructor has been mutated.Expected behavior: The exceptions listed in
repr(exc_grp)matchexc_grp.exceptions, which is immutable.Reproducer:
Output:
Expected output:
CPython versions tested on:
3.11, 3.12, 3.13, 3.14
Operating systems tested on:
Linux
Linked PRs
ExceptionGrouprepr changing when original exception sequence is mutated #141736ExceptionGrouprepr changing when original exception sequence is mutated (GH-141736) #142388