Commit d5d77aac authored by Benjamin Peterson's avatar Benjamin Peterson

set items in dict displays from left to right (closes #24569)

parent 1554b178
......@@ -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
......
......@@ -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
-------
......
......@@ -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();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment