]> granicus.if.org Git - python/commitdiff
Fix a bug in the way __getnewargs__ was handled.
authorGuido van Rossum <guido@python.org>
Thu, 6 Feb 2003 21:25:12 +0000 (21:25 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 6 Feb 2003 21:25:12 +0000 (21:25 +0000)
Lib/copy.py
Lib/test/test_copy.py

index 9f8386e0bdcdea4e175419488f3a682b5844161a..739cf2d7cd83a9d47ed56fbeb40392f55f64fa6d 100644 (file)
@@ -128,7 +128,7 @@ def _better_reduce(obj):
         listitems = iter(obj)
     elif isinstance(obj, dict):
         dictitems = obj.iteritems()
-    return __newobj__, (cls, args), state, listitems, dictitems
+    return __newobj__, (cls,) + args, state, listitems, dictitems
     
 
 _copy_dispatch = d = {}
index 846e675cf4b9bc4c131d37493f0f7a9697062d4d..c97d54d749102b5a01185094aa825948a823cc93 100644 (file)
@@ -454,6 +454,24 @@ class TestCopy(unittest.TestCase):
         self.assert_(x[0] is not y[0])
         self.assert_(x.foo is not y.foo)
 
+    def test_copy_tuple_subclass(self):
+        class C(tuple):
+            pass
+        x = C([1, 2, 3])
+        self.assertEqual(tuple(x), (1, 2, 3))
+        y = copy.copy(x)
+        self.assertEqual(tuple(y), (1, 2, 3))
+
+    def test_deepcopy_tuple_subclass(self):
+        class C(tuple):
+            pass
+        x = C([[1, 2], 3])
+        self.assertEqual(tuple(x), ([1, 2], 3))
+        y = copy.deepcopy(x)
+        self.assertEqual(tuple(y), ([1, 2], 3))
+        self.assert_(x is not y)
+        self.assert_(x[0] is not y[0])
+
 def test_main():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(TestCopy))