mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-27141: Fix collections.UserList and UserDict shallow copy. (GH-4094)
This commit is contained in:
parent
c661b30f89
commit
f4e1babf44
3 changed files with 41 additions and 0 deletions
|
@ -37,6 +37,20 @@ class TestUserObjects(unittest.TestCase):
|
|||
b=b.__name__,
|
||||
),
|
||||
)
|
||||
|
||||
def _copy_test(self, obj):
|
||||
# Test internal copy
|
||||
obj_copy = obj.copy()
|
||||
self.assertIsNot(obj.data, obj_copy.data)
|
||||
self.assertEqual(obj.data, obj_copy.data)
|
||||
|
||||
# Test copy.copy
|
||||
obj.test = [1234] # Make sure instance vars are also copied.
|
||||
obj_copy = copy.copy(obj)
|
||||
self.assertIsNot(obj.data, obj_copy.data)
|
||||
self.assertEqual(obj.data, obj_copy.data)
|
||||
self.assertIs(obj.test, obj_copy.test)
|
||||
|
||||
def test_str_protocol(self):
|
||||
self._superset_test(UserString, str)
|
||||
|
||||
|
@ -46,6 +60,16 @@ class TestUserObjects(unittest.TestCase):
|
|||
def test_dict_protocol(self):
|
||||
self._superset_test(UserDict, dict)
|
||||
|
||||
def test_list_copy(self):
|
||||
obj = UserList()
|
||||
obj.append(123)
|
||||
self._copy_test(obj)
|
||||
|
||||
def test_dict_copy(self):
|
||||
obj = UserDict()
|
||||
obj[123] = "abc"
|
||||
self._copy_test(obj)
|
||||
|
||||
|
||||
################################################################################
|
||||
### ChainMap (helper class for configparser and the string module)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue