Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d5d77aa

Browse files
committed
set items in dict displays from left to right (closes #24569)
1 parent 1554b17 commit d5d77aa

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

Lib/test/test_unpack_ex.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@
128128
... for i in range(1000)) + "}"))
129129
1000
130130
131+
>>> {0:1, **{0:2}, 0:3, 0:4}
132+
{0: 4}
133+
131134
List comprehension element unpacking
132135
133136
>>> a, b, c = [0, 1, 2], 3, 4

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ What's New in Python 3.5.0 beta 4?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #24569: Make PEP 448 dictionary evaluation more consistent.
14+
1315
Library
1416
-------
1517

Python/ceval.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2561,22 +2561,25 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
25612561
}
25622562

25632563
TARGET(BUILD_MAP) {
2564+
int i;
25642565
PyObject *map = _PyDict_NewPresized((Py_ssize_t)oparg);
25652566
if (map == NULL)
25662567
goto error;
2567-
while (--oparg >= 0) {
2568+
for (i = oparg; i > 0; i--) {
25682569
int err;
2569-
PyObject *value = TOP();
2570-
PyObject *key = SECOND();
2571-
STACKADJ(-2);
2570+
PyObject *key = PEEK(2*i);
2571+
PyObject *value = PEEK(2*i - 1);
25722572
err = PyDict_SetItem(map, key, value);
2573-
Py_DECREF(value);
2574-
Py_DECREF(key);
25752573
if (err != 0) {
25762574
Py_DECREF(map);
25772575
goto error;
25782576
}
25792577
}
2578+
2579+
while (oparg--) {
2580+
Py_DECREF(POP());
2581+
Py_DECREF(POP());
2582+
}
25802583
PUSH(map);
25812584
DISPATCH();
25822585
}

0 commit comments

Comments
 (0)