mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-03-14 08:26:37 +01:00
CPython fixed https://github.com/python/cpython/issues/141732 in https://github.com/python/cpython/pull/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: https://github.com/agronholm/exceptiongroup/issues/154
48 lines
1.9 KiB
Diff
48 lines
1.9 KiB
Diff
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
|
|
|