mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Merged revisions 84495-84497 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r84495 | antoine.pitrou | 2010-09-04 19:40:21 +0200 (sam., 04 sept. 2010) | 4 lines Issue #1100562: Fix deep-copying of objects derived from the list and dict types. Patch by Michele Orrù and Björn Lindqvist. ........ r84496 | antoine.pitrou | 2010-09-04 19:40:51 +0200 (sam., 04 sept. 2010) | 3 lines Fix Björn's name in ACKS. ........ r84497 | antoine.pitrou | 2010-09-04 19:46:44 +0200 (sam., 04 sept. 2010) | 3 lines Fix running the copy module from the command-line (however use{ful,less} it may be). ........
This commit is contained in:
parent
5c78edae51
commit
ce111caaeb
4 changed files with 49 additions and 13 deletions
|
@ -532,6 +532,26 @@ class TestCopy(unittest.TestCase):
|
|||
self.assertEqual(x.foo, y.foo)
|
||||
self.assertTrue(x.foo is not y.foo)
|
||||
|
||||
def test_deepcopy_dict_subclass(self):
|
||||
class C(dict):
|
||||
def __init__(self, d=None):
|
||||
if not d:
|
||||
d = {}
|
||||
self._keys = list(d.keys())
|
||||
super().__init__(d)
|
||||
def __setitem__(self, key, item):
|
||||
super().__setitem__(key, item)
|
||||
if key not in self._keys:
|
||||
self._keys.append(key)
|
||||
x = C(d={'foo':0})
|
||||
y = copy.deepcopy(x)
|
||||
self.assertEqual(x, y)
|
||||
self.assertEqual(x._keys, y._keys)
|
||||
self.assertTrue(x is not y)
|
||||
x['bar'] = 1
|
||||
self.assertNotEqual(x, y)
|
||||
self.assertNotEqual(x._keys, y._keys)
|
||||
|
||||
def test_copy_list_subclass(self):
|
||||
class C(list):
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue