Skip to content

Commit

Permalink
bpo-40116: dict: Add regression test for iteration order. (GH-31550)
Browse files Browse the repository at this point in the history
  • Loading branch information
methane committed Mar 3, 2022
1 parent a8c87a2 commit 4f74052
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
17 changes: 17 additions & 0 deletions Lib/test/test_dict.py
Expand Up @@ -1077,6 +1077,23 @@ def test_splittable_popitem(self):
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"}
Expand Down
@@ -0,0 +1,2 @@
Fix regression that dict.update(other) may don't respect iterate order of
other when other is key sharing dict.
@@ -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.

0 comments on commit 4f74052

Please sign in to comment.