bpo-35224: Reverse evaluation order of key: value in dict comprehensions (GH-14139)

… as proposed in PEP 572; key is now evaluated before value.

https://bugs.python.org/issue35224
(cherry picked from commit c8a35417db)

Co-authored-by: Jörn Heissler <joernheissler@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2019-06-22 15:34:03 -07:00 committed by GitHub
parent fa23bd286f
commit 874ff65e0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 53 additions and 7 deletions

View file

@ -2944,8 +2944,8 @@ main_loop:
}
case TARGET(MAP_ADD): {
PyObject *key = TOP();
PyObject *value = SECOND();
PyObject *value = TOP();
PyObject *key = SECOND();
PyObject *map;
int err;
STACK_SHRINK(2);

View file

@ -4238,10 +4238,10 @@ compiler_sync_comprehension_generator(struct compiler *c,
ADDOP_I(c, SET_ADD, gen_index + 1);
break;
case COMP_DICTCOMP:
/* With 'd[k] = v', v is evaluated before k, so we do
/* With '{k: v}', k is evaluated before v, so we do
the same. */
VISIT(c, expr, val);
VISIT(c, expr, elt);
VISIT(c, expr, val);
ADDOP_I(c, MAP_ADD, gen_index + 1);
break;
default:
@ -4327,10 +4327,10 @@ compiler_async_comprehension_generator(struct compiler *c,
ADDOP_I(c, SET_ADD, gen_index + 1);
break;
case COMP_DICTCOMP:
/* With 'd[k] = v', v is evaluated before k, so we do
/* With '{k: v}', k is evaluated before v, so we do
the same. */
VISIT(c, expr, val);
VISIT(c, expr, elt);
VISIT(c, expr, val);
ADDOP_I(c, MAP_ADD, gen_index + 1);
break;
default: