-
-
Notifications
You must be signed in to change notification settings - Fork 23
Fix ExceptionGroup repr changing when original exception sequence is mutated #154
Description
Things to check first
-
I have searched the existing issues and didn't find my bug already reported there
-
I have checked that my bug is still present in the latest release
Exceptiongroup version
1.3.1
Python version
3.13.12
What happened?
CPython fixed python/cpython#141732 in python/cpython#141736, but exceptiongroup 1.3.1, including its test suite, still mirrors / tests for the old (misleading) repr behavior.
One thing to note is that the CPython fix has only been backported to 3.13 so far, where it was first included in version 3.13.12. Therefore exceptiongroup 1.3.1 doesn't correctly mirror the behavior of Python version 3.13.12 (and the latest Python 3.15 versions) anymore and its test suite fails on these versions:
=================================== FAILURES ===================================
___________________ test_exceptions_mutate_original_sequence ___________________
tests/test_exceptions.py:885: in test_exceptions_mutate_original_sequence
assert repr(excgrp) == (
E assert "BaseExceptionGroup('foo', [ValueError(1), KeyboardInterrupt()])" == "BaseExceptionGroup('foo', [ValueError(1), KeyboardInterrupt(), KeyError('bar')])"
E
E - BaseExceptionGroup('foo', [ValueError(1), KeyboardInterrupt(), KeyError('bar')])
E ? -----------------
E + BaseExceptionGroup('foo', [ValueError(1), KeyboardInterrupt()])
I came up with a patch that should make exceptiongroup mirror the repr behavior of the affected Python versions correctly, but note that it currently doesn't differentiate between Python versions (e.g., it won't correctly mirror upstream behavior on Python 3.14).
How can we reproduce the bug?
- Run the test suite on Python 3.13.12 or Python 3.15.0a3 (or a later patch/alpha version, respectively)