mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-40116: Add insertion order bit-vector to dict values to allow dicts to share keys more freely. (GH-28520)
This commit is contained in:
parent
f6eafe18c0
commit
a7252f88d3
8 changed files with 176 additions and 187 deletions
|
@ -1020,7 +1020,6 @@ class DictTest(unittest.TestCase):
|
|||
with self.assertRaises(KeyError):
|
||||
del a['y']
|
||||
|
||||
self.assertGreater(sys.getsizeof(a), orig_size)
|
||||
self.assertEqual(list(a), ['x', 'z'])
|
||||
self.assertEqual(list(b), ['x', 'y', 'z'])
|
||||
|
||||
|
@ -1031,16 +1030,12 @@ class DictTest(unittest.TestCase):
|
|||
|
||||
@support.cpython_only
|
||||
def test_splittable_pop(self):
|
||||
"""split table must be combined when d.pop(k)"""
|
||||
a, b = self.make_shared_key_dict(2)
|
||||
|
||||
orig_size = sys.getsizeof(a)
|
||||
|
||||
a.pop('y') # split table is combined
|
||||
a.pop('y')
|
||||
with self.assertRaises(KeyError):
|
||||
a.pop('y')
|
||||
|
||||
self.assertGreater(sys.getsizeof(a), orig_size)
|
||||
self.assertEqual(list(a), ['x', 'z'])
|
||||
self.assertEqual(list(b), ['x', 'y', 'z'])
|
||||
|
||||
|
@ -1074,36 +1069,6 @@ class DictTest(unittest.TestCase):
|
|||
self.assertEqual(list(a), ['x', 'y'])
|
||||
self.assertEqual(list(b), ['x', 'y', 'z'])
|
||||
|
||||
@support.cpython_only
|
||||
def test_splittable_setattr_after_pop(self):
|
||||
"""setattr() must not convert combined table into split table."""
|
||||
# Issue 28147
|
||||
import _testcapi
|
||||
|
||||
class C:
|
||||
pass
|
||||
a = C()
|
||||
|
||||
a.a = 1
|
||||
self.assertTrue(_testcapi.dict_hassplittable(a.__dict__))
|
||||
|
||||
# dict.pop() convert it to combined table
|
||||
a.__dict__.pop('a')
|
||||
self.assertFalse(_testcapi.dict_hassplittable(a.__dict__))
|
||||
|
||||
# But C should not convert a.__dict__ to split table again.
|
||||
a.a = 1
|
||||
self.assertFalse(_testcapi.dict_hassplittable(a.__dict__))
|
||||
|
||||
# Same for popitem()
|
||||
a = C()
|
||||
a.a = 2
|
||||
self.assertTrue(_testcapi.dict_hassplittable(a.__dict__))
|
||||
a.__dict__.popitem()
|
||||
self.assertFalse(_testcapi.dict_hassplittable(a.__dict__))
|
||||
a.a = 3
|
||||
self.assertFalse(_testcapi.dict_hassplittable(a.__dict__))
|
||||
|
||||
def test_iterator_pickling(self):
|
||||
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||
data = {1:"a", 2:"b", 3:"c"}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue