nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at r-updates 48 lines 1.9 kB view raw
1From 9be2b65dbd8366da27cd79c09195493217dbf539 Mon Sep 17 00:00:00 2001 2From: Tom Hunze <dev@thunze.de> 3Date: Sat, 7 Feb 2026 11:37:49 +0100 4Subject: [PATCH] Fix `ExceptionGroup` repr changing when original exception 5 sequence is mutated 6 7https://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 13diff --git a/src/exceptiongroup/_exceptions.py b/src/exceptiongroup/_exceptions.py 14index 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): 34diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py 35index 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-- 472.51.2 48