From 294b175b8b1507d80efd7dd2407eb45770e695d2 Mon Sep 17 00:00:00 2001 From: Tom Hunze Date: Sat, 7 Feb 2026 11:53:40 +0100 Subject: [PATCH] python3Packages.exceptiongroup: fix build after cpython repr changes 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 --- .../python-modules/exceptiongroup/default.nix | 10 ++++ .../exceptiongroup/match-repr-fix.patch | 48 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 pkgs/development/python-modules/exceptiongroup/match-repr-fix.patch diff --git a/pkgs/development/python-modules/exceptiongroup/default.nix b/pkgs/development/python-modules/exceptiongroup/default.nix index ac3ac7e676d9..d55affdc2484 100644 --- a/pkgs/development/python-modules/exceptiongroup/default.nix +++ b/pkgs/development/python-modules/exceptiongroup/default.nix @@ -6,6 +6,7 @@ pytestCheckHook, pythonAtLeast, pythonOlder, + isPy313, typing-extensions, }: @@ -21,6 +22,15 @@ buildPythonPackage rec { hash = "sha256-3WInufN+Pp6vB/Gik6e8V1a34Dr/oiH3wDMB+2lHRMM="; }; + # 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 + patches = lib.optional (isPy313 || pythonAtLeast "3.15") ./match-repr-fix.patch; + build-system = [ flit-scm ]; dependencies = lib.optionals (pythonOlder "3.13") [ typing-extensions ]; diff --git a/pkgs/development/python-modules/exceptiongroup/match-repr-fix.patch b/pkgs/development/python-modules/exceptiongroup/match-repr-fix.patch new file mode 100644 index 000000000000..ed09c9f39600 --- /dev/null +++ b/pkgs/development/python-modules/exceptiongroup/match-repr-fix.patch @@ -0,0 +1,48 @@ +From 9be2b65dbd8366da27cd79c09195493217dbf539 Mon Sep 17 00:00:00 2001 +From: Tom Hunze +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 +