Commit 2ec8f9bf authored by Benjamin Peterson's avatar Benjamin Peterson

merge 3.5 (#11205)

parents 26f7057b ee85339c
......@@ -221,12 +221,13 @@ _code_type = type(_write_atomic.__code__)
# Python 3.4rc2 3310 (alter __qualname__ computation)
# Python 3.5a0 3320 (matrix multiplication operator)
# Python 3.5b1 3330 (PEP 448: Additional Unpacking Generalizations)
# Python 3.5b2 3340 (fix dictionary display evaluation order #11205)
#
# MAGIC must change whenever the bytecode emitted by the compiler may no
# longer be understood by older implementations of the eval loop (usually
# due to the addition of new opcodes).
MAGIC_NUMBER = (3330).to_bytes(2, 'little') + b'\r\n'
MAGIC_NUMBER = (3340).to_bytes(2, 'little') + b'\r\n'
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
_PYCACHE = '__pycache__'
......
......@@ -461,6 +461,17 @@ if 1:
ast.body = [_ast.BoolOp()]
self.assertRaises(TypeError, compile, ast, '<ast>', 'exec')
def test_dict_evaluation_order(self):
i = 0
def f():
nonlocal i
i += 1
return i
d = {f(): f(), f(): f()}
self.assertEqual(d, {1: 2, 3: 4})
@support.cpython_only
def test_same_filename_used(self):
s = """def f(): pass\ndef g(): pass"""
......
......@@ -22,6 +22,8 @@ Release date: 2015-07-05
Core and Builtins
-----------------
- Issue #11205: In dictionary displays, evaluate the key before the value.
- Issue #24285: Fixed regression that prevented importing extension modules
from inside packages. Patch by Petr Viktorin.
......
......@@ -2584,8 +2584,8 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
goto error;
while (--oparg >= 0) {
int err;
PyObject *key = TOP();
PyObject *value = SECOND();
PyObject *value = TOP();
PyObject *key = SECOND();
STACKADJ(-2);
err = PyDict_SetItem(map, key, value);
Py_DECREF(value);
......
......@@ -3138,8 +3138,8 @@ compiler_dict(struct compiler *c, expr_ty e)
containers++;
}
else {
VISIT(c, expr, (expr_ty)asdl_seq_GET(e->v.Dict.values, i));
VISIT(c, expr, (expr_ty)asdl_seq_GET(e->v.Dict.keys, i));
VISIT(c, expr, (expr_ty)asdl_seq_GET(e->v.Dict.values, i));
elements++;
}
}
......@@ -3287,8 +3287,8 @@ compiler_call_helper(struct compiler *c,
}
else if (nsubkwargs) {
/* A keyword argument and we already have a dict. */
VISIT(c, expr, kw->value);
ADDOP_O(c, LOAD_CONST, kw->arg, consts);
VISIT(c, expr, kw->value);
nseen++;
}
else {
......
This diff is collapsed.
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