Skip to content

Commit 4f74052

Browse files
authored
bpo-40116: dict: Add regression test for iteration order. (GH-31550)
1 parent a8c87a2 commit 4f74052

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

Lib/test/test_dict.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,23 @@ def test_splittable_popitem(self):
10771077
self.assertEqual(list(a), ['x', 'y'])
10781078
self.assertEqual(list(b), ['x', 'y', 'z'])
10791079

1080+
@support.cpython_only
1081+
def test_splittable_update(self):
1082+
"""dict.update(other) must preserve order in other."""
1083+
class C:
1084+
def __init__(self, order):
1085+
if order:
1086+
self.a, self.b, self.c = 1, 2, 3
1087+
else:
1088+
self.c, self.b, self.a = 1, 2, 3
1089+
o = C(True)
1090+
o = C(False) # o.__dict__ has reversed order.
1091+
self.assertEqual(list(o.__dict__), ["c", "b", "a"])
1092+
1093+
d = {}
1094+
d.update(o.__dict__)
1095+
self.assertEqual(list(d), ["c", "b", "a"])
1096+
10801097
def test_iterator_pickling(self):
10811098
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
10821099
data = {1:"a", 2:"b", 3:"c"}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix regression that dict.update(other) may don't respect iterate order of
2+
other when other is key sharing dict.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
In :func:`typing.get_type_hints`, support evaluating stringified ``ParamSpecArgs`` and ``ParamSpecKwargs`` annotations. Patch by Gregory Beauregard.
1+
In :func:`typing.get_type_hints`, support evaluating stringified ``ParamSpecArgs`` and ``ParamSpecKwargs`` annotations. Patch by Gregory Beauregard.

0 commit comments

Comments
 (0)