Benjamin Peterson <benja...@python.org> added the comment:

I expect you'd have to make the check of test nodes in ast.c stricter. Here's a 
slightly gross implementation of that:

diff --git a/Python/ast.c b/Python/ast.c
index 94962e00c7..b7cebf4777 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -2815,15 +2815,22 @@ ast_for_call(struct compiling *c, const node *n, 
expr_ty func, bool allowgen)
                 identifier key, tmp;
                 int k;
 
-                /* chch is test, but must be an identifier? */
-                e = ast_for_expr(c, chch);
-                if (!e)
+                static const int chain[] = {test, or_test, and_test, not_test, 
comparison, expr, xor_expr, and_expr, shift_expr, arith_expr, term, factor, 
power, atom_expr, atom, 0};
+
+                node *expr_node = chch;
+                for (int i = 0; chain[i]; i++) {
+                    if (TYPE(expr_node) != chain[i])
+                        break;
+                    if (NCH(expr_node) != 1)
+                        break;
+                    expr_node = CHILD(expr_node, 0);
+                }
+                if (TYPE(expr_node) != NAME) {
+                    ast_error(c, chch,
+                            "keyword can't be an expression");
                     return NULL;
-                /* f(lambda x: x[0] = 3) ends up getting parsed with
-                 * LHS test = lambda x: x[0], and RHS test = 3.
-                 * SF bug 132313 points out that complaining about a keyword
-                 * then is very confusing.
-                 */
+                }
+                e = ast_for_expr(c, chch);
                 if (e->kind == Lambda_kind) {
                     ast_error(c, chch,
                             "lambda cannot contain assignment");

----------
nosy: +benjamin.peterson

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue34641>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to