This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author benjamin.peterson
Recipients benjamin.peterson, emilyemorehouse, gvanrossum
Date 2018-09-12.01:21:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1536715293.47.0.0269046726804.issue34641@psf.upfronthosting.co.za>
In-reply-to
Content
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");
History
Date User Action Args
2018-09-12 01:21:33benjamin.petersonsetrecipients: + benjamin.peterson, gvanrossum, emilyemorehouse
2018-09-12 01:21:33benjamin.petersonsetmessageid: <1536715293.47.0.0269046726804.issue34641@psf.upfronthosting.co.za>
2018-09-12 01:21:33benjamin.petersonlinkissue34641 messages
2018-09-12 01:21:32benjamin.petersoncreate