[3.13] improve test_copy_reduce and test_deepcopy_reduce coverage (GH-154182) (#155794)

tomasr8 <[email protected]>
Newsgroups gmane.comp.python.cvs
Message-ID <[email protected]>
https://github.com/python/cpython/commit/89d7d3e2b7082e2bee9072feda061539b1a9be76
commit: 89d7d3e2b7082e2bee9072feda061539b1a9be76
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: tomasr8 <[email protected]>
date: 2026-08-14T13:03:50Z
summary:

[3.13] improve test_copy_reduce and test_deepcopy_reduce coverage (GH-154182) (#155794)

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 <[email protected]>
Co-authored-by: Tomas R. <[email protected]>

files:
M Lib/test/test_copy.py

diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py
index 69a981cd14ca7b..23f864daa2e60f 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)

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.