Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 85233bf

Browse files
committed
Fix a bug in the way __getnewargs__ was handled.
1 parent 694d9b3 commit 85233bf

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

Lib/copy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def _better_reduce(obj):
128128
listitems = iter(obj)
129129
elif isinstance(obj, dict):
130130
dictitems = obj.iteritems()
131-
return __newobj__, (cls, args), state, listitems, dictitems
131+
return __newobj__, (cls,) + args, state, listitems, dictitems
132132

133133

134134
_copy_dispatch = d = {}

Lib/test/test_copy.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,24 @@ class C(list):
454454
self.assert_(x[0] is not y[0])
455455
self.assert_(x.foo is not y.foo)
456456

457+
def test_copy_tuple_subclass(self):
458+
class C(tuple):
459+
pass
460+
x = C([1, 2, 3])
461+
self.assertEqual(tuple(x), (1, 2, 3))
462+
y = copy.copy(x)
463+
self.assertEqual(tuple(y), (1, 2, 3))
464+
465+
def test_deepcopy_tuple_subclass(self):
466+
class C(tuple):
467+
pass
468+
x = C([[1, 2], 3])
469+
self.assertEqual(tuple(x), ([1, 2], 3))
470+
y = copy.deepcopy(x)
471+
self.assertEqual(tuple(y), ([1, 2], 3))
472+
self.assert_(x is not y)
473+
self.assert_(x[0] is not y[0])
474+
457475
def test_main():
458476
suite = unittest.TestSuite()
459477
suite.addTest(unittest.makeSuite(TestCopy))

0 commit comments

Comments
 (0)