From 0e196932a338cfa489305303521c6c0309e6edd5 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 14 Aug 2026 14:41:31 +0200 Subject: [PATCH] improve test_copy_reduce and test_deepcopy_reduce coverage (GH-154182) * improve test_copy_reduce and test_deepcopy_reduce coverage * add assert __reduce_ex__ not called * change reduce params in test copy and deepcopy reduce_ex * change reduce_ex params in test copy and deepcopy reduce --------- (cherry picked from commit 4af81d9215a8f267c5caeecf98c789999c108f80) Co-authored-by: David Co-authored-by: Tomas R. --- Lib/test/test_copy.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py index b452ddbef5ccbee..9db033a65ba7dd7 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() @@ -70,9 +70,15 @@ def __reduce__(self): def test_copy_reduce(self): class C(object): + def __reduce_ex__(*args): + self.fail("shouldn't call this") 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) @@ -323,7 +329,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() @@ -333,9 +339,15 @@ def __reduce__(self): def test_deepcopy_reduce(self): class C(object): + def __reduce_ex__(*args): + self.fail("shouldn't call this") 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)