mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
bpo-40334: Correctly identify invalid target in assignment errors (GH-20076)
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
This commit is contained in:
parent
7ba1f75f3f
commit
16ab07063c
10 changed files with 137 additions and 45 deletions
13
Python/ast.c
13
Python/ast.c
|
@ -3164,10 +3164,7 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
|
|||
expr1 = ast_for_testlist(c, ch);
|
||||
if (!expr1)
|
||||
return NULL;
|
||||
if(!set_context(c, expr1, Store, ch))
|
||||
return NULL;
|
||||
/* set_context checks that most expressions are not the left side.
|
||||
Augmented assignments can only have a name, a subscript, or an
|
||||
/* Augmented assignments can only have a name, a subscript, or an
|
||||
attribute on the left, though, so we have to explicitly check for
|
||||
those. */
|
||||
switch (expr1->kind) {
|
||||
|
@ -3176,10 +3173,16 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
|
|||
case Subscript_kind:
|
||||
break;
|
||||
default:
|
||||
ast_error(c, ch, "illegal expression for augmented assignment");
|
||||
ast_error(c, ch, "'%s' is an illegal expression for augmented assignment",
|
||||
get_expr_name(expr1));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* set_context checks that most expressions are not the left side. */
|
||||
if(!set_context(c, expr1, Store, ch)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ch = CHILD(n, 2);
|
||||
if (TYPE(ch) == testlist)
|
||||
expr2 = ast_for_testlist(c, ch);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue