From f5f296cf32c27be6a970e4c568450846f3f01be5 Mon Sep 17 00:00:00 2001 From: David Slavicek Date: Sun, 19 Jul 2026 19:54:36 +0200 Subject: [PATCH 1/3] improve test_copy_reduce and test_deepcopy_reduce coverage --- Lib/test/test_copy.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py index 98f56b5ae87f96..71bbccbe32be58 100644 --- a/Lib/test/test_copy.py +++ b/Lib/test/test_copy.py @@ -73,6 +73,10 @@ class C(object): def __reduce__(self): c.append(1) return "" + def __getattribute__(self, name): + if name == "__reduce_ex__": + raise AttributeError(name) + return object.__getattribute__(self, name) c = [] x = C() y = copy.copy(x) @@ -342,6 +346,10 @@ class C(object): def __reduce__(self): c.append(1) return "" + def __getattribute__(self, name): + if name == "__reduce_ex__": + raise AttributeError(name) + return object.__getattribute__(self, name) c = [] x = C() y = copy.deepcopy(x) From 1413c2e4f18a0181141b0fedd1d988e84771178f Mon Sep 17 00:00:00 2001 From: David Slavicek Date: Thu, 23 Jul 2026 22:08:16 +0200 Subject: [PATCH 2/3] add assert __reduce_ex__ not called --- Lib/test/test_copy.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py index 71bbccbe32be58..9a0571afcb8dfc 100644 --- a/Lib/test/test_copy.py +++ b/Lib/test/test_copy.py @@ -70,6 +70,8 @@ def __reduce__(self): def test_copy_reduce(self): class C(object): + def __reduce_ex__(self, proto): + self.fail("shouldn't call this") def __reduce__(self): c.append(1) return "" @@ -343,6 +345,8 @@ def __reduce__(self): def test_deepcopy_reduce(self): class C(object): + def __reduce_ex__(self, proto): + self.fail("shouldn't call this") def __reduce__(self): c.append(1) return "" From 8d02f699d659fca89165498e5a7d754bcd2b4bde Mon Sep 17 00:00:00 2001 From: David Slavicek Date: Thu, 23 Jul 2026 22:35:03 +0200 Subject: [PATCH 3/3] change reduce params in test copy and deepcopy reduce_ex --- Lib/test/test_copy.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py index 9a0571afcb8dfc..0e2021220433e0 100644 --- a/Lib/test/test_copy.py +++ b/Lib/test/test_copy.py @@ -60,7 +60,7 @@ class C(object): def __reduce_ex__(self, proto): c.append(1) return "" - def __reduce__(self): + def __reduce__(*args): self.fail("shouldn't call this") c = [] x = C() @@ -335,7 +335,7 @@ class C(object): def __reduce_ex__(self, proto): c.append(1) return "" - def __reduce__(self): + def __reduce__(*args): self.fail("shouldn't call this") c = [] x = C()