From d5d77aac60453694445d1509b51d7514871dbff8 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sun, 5 Jul 2015 10:37:25 -0500 Subject: [PATCH] set items in dict displays from left to right (closes #24569) --- Lib/test/test_unpack_ex.py | 3 +++ Misc/NEWS | 2 ++ Python/ceval.c | 15 +++++++++------ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_unpack_ex.py b/Lib/test/test_unpack_ex.py index 01f57b95e75..d27eef03972 100644 --- a/Lib/test/test_unpack_ex.py +++ b/Lib/test/test_unpack_ex.py @@ -128,6 +128,9 @@ Dict display element unpacking ... for i in range(1000)) + "}")) 1000 + >>> {0:1, **{0:2}, 0:3, 0:4} + {0: 4} + List comprehension element unpacking >>> a, b, c = [0, 1, 2], 3, 4 diff --git a/Misc/NEWS b/Misc/NEWS index b9cf2bcbf13..46881c334fb 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ What's New in Python 3.5.0 beta 4? Core and Builtins ----------------- +- Issue #24569: Make PEP 448 dictionary evaluation more consistent. + Library ------- diff --git a/Python/ceval.c b/Python/ceval.c index e68ae33bfd7..ac52ad91e21 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2561,22 +2561,25 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) } TARGET(BUILD_MAP) { + int i; PyObject *map = _PyDict_NewPresized((Py_ssize_t)oparg); if (map == NULL) goto error; - while (--oparg >= 0) { + for (i = oparg; i > 0; i--) { int err; - PyObject *value = TOP(); - PyObject *key = SECOND(); - STACKADJ(-2); + PyObject *key = PEEK(2*i); + PyObject *value = PEEK(2*i - 1); err = PyDict_SetItem(map, key, value); - Py_DECREF(value); - Py_DECREF(key); if (err != 0) { Py_DECREF(map); goto error; } } + + while (oparg--) { + Py_DECREF(POP()); + Py_DECREF(POP()); + } PUSH(map); DISPATCH(); }