summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/exceptiongroup/match-repr-fix.patch
blob: ed09c9f39600c2f67c9cae26b0da3bc1637d446f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
From 9be2b65dbd8366da27cd79c09195493217dbf539 Mon Sep 17 00:00:00 2001
From: Tom Hunze <dev@thunze.de>
Date: Sat, 7 Feb 2026 11:37:49 +0100
Subject: [PATCH] Fix `ExceptionGroup` repr changing when original exception
 sequence is mutated

https://github.com/python/cpython/pull/141736
---
 src/exceptiongroup/_exceptions.py | 3 ++-
 tests/test_exceptions.py          | 3 +--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/exceptiongroup/_exceptions.py b/src/exceptiongroup/_exceptions.py
index f42c1ad..996d8e1 100644
--- a/src/exceptiongroup/_exceptions.py
+++ b/src/exceptiongroup/_exceptions.py
@@ -101,6 +101,7 @@ class BaseExceptionGroup(BaseException, Generic[_BaseExceptionT_co]):
                         )
 
         instance = super().__new__(cls, __message, __exceptions)
+        instance._exceptions_str = repr(__exceptions)
         instance._exceptions = tuple(__exceptions)
         return instance
 
@@ -275,7 +276,7 @@ class BaseExceptionGroup(BaseException, Generic[_BaseExceptionT_co]):
         return f"{self.message} ({len(self._exceptions)} sub-exception{suffix})"
 
     def __repr__(self) -> str:
-        return f"{self.__class__.__name__}({self.args[0]!r}, {self.args[1]!r})"
+        return f"{self.__class__.__name__}({self.args[0]!r}, {self._exceptions_str})"
 
 
 class ExceptionGroup(BaseExceptionGroup[_ExceptionT_co], Exception):
diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py
index e2bc81a..a253236 100644
--- a/tests/test_exceptions.py
+++ b/tests/test_exceptions.py
@@ -883,6 +883,5 @@ def test_exceptions_mutate_original_sequence():
     exceptions.append(KeyError("bar"))
     assert excgrp.exceptions is exc_tuple
     assert repr(excgrp) == (
-        "BaseExceptionGroup('foo', [ValueError(1), KeyboardInterrupt(), "
-        "KeyError('bar')])"
+        "BaseExceptionGroup('foo', [ValueError(1), KeyboardInterrupt()])"
     )
-- 
2.51.2