[Python-checkins] cpython (3.5): set items in dict displays from left to right (closes #24569)

benjamin.peterson python-checkins at python.org
Sun Jul 5 17:39:27 CEST 2015


https://hg.python.org/cpython/rev/a4df0fe62b46
changeset:   96823:a4df0fe62b46
branch:      3.5
user:        Benjamin Peterson <benjamin at python.org>
date:        Sun Jul 05 10:37:25 2015 -0500
summary:
  set items in dict displays from left to right (closes #24569)

files:
  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
--- a/Lib/test/test_unpack_ex.py
+++ b/Lib/test/test_unpack_ex.py
@@ -128,6 +128,9 @@
     ...                          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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@
 Core and Builtins
 -----------------
 
+- Issue #24569: Make PEP 448 dictionary evaluation more consistent.
+
 Library
 -------
 
diff --git a/Python/ceval.c b/Python/ceval.c
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -2561,22 +2561,25 @@
         }
 
         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();
         }

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list