Skip to content

Commit 294b175

Browse files
thunzemweinelt
authored andcommitted
python3Packages.exceptiongroup: fix build after cpython repr changes
CPython fixed python/cpython#141732 in python/cpython#141736, but exceptiongroup 1.3.1, including its test suite, still matches the old repr behavior. The CPython fix has only been backported to 3.13 so far, where it was first included in version 3.13.12, so we only need to patch for 3.13 and 3.15+. Upstream issue: agronholm/exceptiongroup#154
1 parent b0d1142 commit 294b175

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

pkgs/development/python-modules/exceptiongroup/default.nix

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
pytestCheckHook,
77
pythonAtLeast,
88
pythonOlder,
9+
isPy313,
910
typing-extensions,
1011
}:
1112

@@ -21,6 +22,15 @@ buildPythonPackage rec {
2122
hash = "sha256-3WInufN+Pp6vB/Gik6e8V1a34Dr/oiH3wDMB+2lHRMM=";
2223
};
2324

25+
# CPython fixed https://github.com/python/cpython/issues/141732 in
26+
# https://github.com/python/cpython/pull/141736, but exceptiongroup 1.3.1,
27+
# including its test suite, still matches the old repr behavior.
28+
# The CPython fix has only been backported to 3.13 so far, where it was
29+
# first included in version 3.13.12, so we only need to patch for 3.13
30+
# and 3.15+.
31+
# Upstream issue: https://github.com/agronholm/exceptiongroup/issues/154
32+
patches = lib.optional (isPy313 || pythonAtLeast "3.15") ./match-repr-fix.patch;
33+
2434
build-system = [ flit-scm ];
2535

2636
dependencies = lib.optionals (pythonOlder "3.13") [ typing-extensions ];
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
From 9be2b65dbd8366da27cd79c09195493217dbf539 Mon Sep 17 00:00:00 2001
2+
From: Tom Hunze <dev@thunze.de>
3+
Date: Sat, 7 Feb 2026 11:37:49 +0100
4+
Subject: [PATCH] Fix `ExceptionGroup` repr changing when original exception
5+
sequence is mutated
6+
7+
https://github.com/python/cpython/pull/141736
8+
---
9+
src/exceptiongroup/_exceptions.py | 3 ++-
10+
tests/test_exceptions.py | 3 +--
11+
2 files changed, 3 insertions(+), 3 deletions(-)
12+
13+
diff --git a/src/exceptiongroup/_exceptions.py b/src/exceptiongroup/_exceptions.py
14+
index f42c1ad..996d8e1 100644
15+
--- a/src/exceptiongroup/_exceptions.py
16+
+++ b/src/exceptiongroup/_exceptions.py
17+
@@ -101,6 +101,7 @@ class BaseExceptionGroup(BaseException, Generic[_BaseExceptionT_co]):
18+
)
19+
20+
instance = super().__new__(cls, __message, __exceptions)
21+
+ instance._exceptions_str = repr(__exceptions)
22+
instance._exceptions = tuple(__exceptions)
23+
return instance
24+
25+
@@ -275,7 +276,7 @@ class BaseExceptionGroup(BaseException, Generic[_BaseExceptionT_co]):
26+
return f"{self.message} ({len(self._exceptions)} sub-exception{suffix})"
27+
28+
def __repr__(self) -> str:
29+
- return f"{self.__class__.__name__}({self.args[0]!r}, {self.args[1]!r})"
30+
+ return f"{self.__class__.__name__}({self.args[0]!r}, {self._exceptions_str})"
31+
32+
33+
class ExceptionGroup(BaseExceptionGroup[_ExceptionT_co], Exception):
34+
diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py
35+
index e2bc81a..a253236 100644
36+
--- a/tests/test_exceptions.py
37+
+++ b/tests/test_exceptions.py
38+
@@ -883,6 +883,5 @@ def test_exceptions_mutate_original_sequence():
39+
exceptions.append(KeyError("bar"))
40+
assert excgrp.exceptions is exc_tuple
41+
assert repr(excgrp) == (
42+
- "BaseExceptionGroup('foo', [ValueError(1), KeyboardInterrupt(), "
43+
- "KeyError('bar')])"
44+
+ "BaseExceptionGroup('foo', [ValueError(1), KeyboardInterrupt()])"
45+
)
46+
--
47+
2.51.2
48+

0 commit comments

Comments
 (0)