Fix a bug in the way __getnewargs__ was handled.

This commit is contained in:
Guido van Rossum 2003-02-06 21:25:12 +00:00
parent 694d9b3541
commit 85233bf746
2 changed files with 19 additions and 1 deletions

View File

@ -128,7 +128,7 @@ def _better_reduce(obj):
listitems = iter(obj) listitems = iter(obj)
elif isinstance(obj, dict): elif isinstance(obj, dict):
dictitems = obj.iteritems() dictitems = obj.iteritems()
return __newobj__, (cls, args), state, listitems, dictitems return __newobj__, (cls,) + args, state, listitems, dictitems
_copy_dispatch = d = {} _copy_dispatch = d = {}

View File

@ -454,6 +454,24 @@ class TestCopy(unittest.TestCase):
self.assert_(x[0] is not y[0]) self.assert_(x[0] is not y[0])
self.assert_(x.foo is not y.foo) 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(): def test_main():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestCopy)) suite.addTest(unittest.makeSuite(TestCopy))