From 4f74052b455a54ac736f38973693aeea2ec14116 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 3 Mar 2022 13:06:29 +0900 Subject: bpo-40116: dict: Add regression test for iteration order. (GH-31550) --- Lib/test/test_dict.py | 17 +++++++++++++++++ .../2022-02-24-16-34-17.bpo-40116.AeVGG2.rst | 2 ++ .../Library/2022-02-09-22-40-11.bpo-46643.aBlIx1.rst | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-02-24-16-34-17.bpo-40116.AeVGG2.rst diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py index 66f5d56..e60ae43 100644 --- a/Lib/test/test_dict.py +++ b/Lib/test/test_dict.py @@ -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"} diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-02-24-16-34-17.bpo-40116.AeVGG2.rst b/Misc/NEWS.d/next/Core and Builtins/2022-02-24-16-34-17.bpo-40116.AeVGG2.rst new file mode 100644 index 0000000..fb3f82e --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-02-24-16-34-17.bpo-40116.AeVGG2.rst @@ -0,0 +1,2 @@ +Fix regression that dict.update(other) may don't respect iterate order of +other when other is key sharing dict. diff --git a/Misc/NEWS.d/next/Library/2022-02-09-22-40-11.bpo-46643.aBlIx1.rst b/Misc/NEWS.d/next/Library/2022-02-09-22-40-11.bpo-46643.aBlIx1.rst index e8b4d66..82ff831 100644 --- a/Misc/NEWS.d/next/Library/2022-02-09-22-40-11.bpo-46643.aBlIx1.rst +++ b/Misc/NEWS.d/next/Library/2022-02-09-22-40-11.bpo-46643.aBlIx1.rst @@ -1 +1 @@ -In :func:`typing.get_type_hints`, support evaluating stringified ``ParamSpecArgs`` and ``ParamSpecKwargs`` annotations. Patch by Gregory Beauregard. \ No newline at end of file +In :func:`typing.get_type_hints`, support evaluating stringified ``ParamSpecArgs`` and ``ParamSpecKwargs`` annotations. Patch by Gregory Beauregard. -- cgit v0.12