bpo-40116: dict: Add regression test for iteration order. (GH-31550)

This commit is contained in:
Inada Naoki 2022-03-03 13:06:29 +09:00 committed by GitHub
parent a8c87a239e
commit 4f74052b45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View file

@ -1077,6 +1077,23 @@ class DictTest(unittest.TestCase):
self.assertEqual(list(a), ['x', 'y'])
self.assertEqual(list(b), ['x', 'y', 'z'])
@support.cpython_only
def test_splittable_update(self):
"""dict.update(other) must preserve order in other."""
class C:
def __init__(self, order):
if order:
self.a, self.b, self.c = 1, 2, 3
else:
self.c, self.b, self.a = 1, 2, 3
o = C(True)
o = C(False) # o.__dict__ has reversed order.
self.assertEqual(list(o.__dict__), ["c", "b", "a"])
d = {}
d.update(o.__dict__)
self.assertEqual(list(d), ["c", "b", "a"])
def test_iterator_pickling(self):
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
data = {1:"a", 2:"b", 3:"c"}

View file

@ -0,0 +1,2 @@
Fix regression that dict.update(other) may don't respect iterate order of
other when other is key sharing dict.

View file

@ -1 +1 @@
In :func:`typing.get_type_hints`, support evaluating stringified ``ParamSpecArgs`` and ``ParamSpecKwargs`` annotations. Patch by Gregory Beauregard.
In :func:`typing.get_type_hints`, support evaluating stringified ``ParamSpecArgs`` and ``ParamSpecKwargs`` annotations. Patch by Gregory Beauregard.