From 85233bf74679a5dae4365507526789883a3c1158 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 6 Feb 2003 21:25:12 +0000 Subject: Fix a bug in the way __getnewargs__ was handled. --- Lib/copy.py | 2 +- Lib/test/test_copy.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Lib/copy.py b/Lib/copy.py index 9f8386e..739cf2d 100644 --- a/Lib/copy.py +++ b/Lib/copy.py @@ -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 = {} diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py index 846e675..c97d54d 100644 --- a/Lib/test/test_copy.py +++ b/Lib/test/test_copy.py @@ -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)) -- cgit v0.12