Message325111
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"); |
|
Date |
User |
Action |
Args |
2018-09-12 01:21:33 | benjamin.peterson | set | recipients:
+ benjamin.peterson, gvanrossum, emilyemorehouse |
2018-09-12 01:21:33 | benjamin.peterson | set | messageid: <1536715293.47.0.0269046726804.issue34641@psf.upfronthosting.co.za> |
2018-09-12 01:21:33 | benjamin.peterson | link | issue34641 messages |
2018-09-12 01:21:32 | benjamin.peterson | create | |
|