summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-06-22 15:34:03 -0700
committerGitHub <noreply@github.com>2019-06-22 15:34:03 -0700
commit874ff65e0a70ff4fd1a67e85cd61d76adfcc219d (patch)
tree56f0a7d275a2283001ce6ca87168d000c995438c /Python
parentfa23bd286fb7719bd7601da0b713457589f5536f (diff)
downloadcpython-git-874ff65e0a70ff4fd1a67e85cd61d76adfcc219d.tar.gz
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 c8a35417db8853a253517a3e5190e174075c6384) Co-authored-by: Jörn Heissler <joernheissler@users.noreply.github.com>
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c4
-rw-r--r--Python/compile.c8
2 files changed, 6 insertions, 6 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 7063647d58..eddcc8d8b4 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -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);
diff --git a/Python/compile.c b/Python/compile.c
index 4d3ecfe5d6..7bdf406079 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -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: