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

This commit is contained in:
Benjamin Peterson 2015-07-05 10:37:25 -05:00
parent 1554b17856
commit d5d77aac60
3 changed files with 14 additions and 6 deletions

View File

@ -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

View File

@ -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
-------

View File

@ -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();
}