mirror of
https://github.com/python/cpython.git
synced 2026-01-06 07:22:09 +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
|
|
@ -640,8 +640,17 @@ invalid_assignment:
|
|||
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not tuple) can be annotated") }
|
||||
| a=expression ':' expression ['=' annotated_rhs] {
|
||||
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "illegal target for annotation") }
|
||||
| a=expression ('=' | augassign) (yield_expr | star_expressions) {
|
||||
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot assign to %s", _PyPegen_get_expr_name(a)) }
|
||||
| a=star_expressions '=' (yield_expr | star_expressions) {
|
||||
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
|
||||
_PyPegen_get_invalid_target(a),
|
||||
"cannot assign to %s", _PyPegen_get_expr_name(_PyPegen_get_invalid_target(a))) }
|
||||
| a=star_expressions augassign (yield_expr | star_expressions) {
|
||||
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
|
||||
a,
|
||||
"'%s' is an illegal expression for augmented assignment",
|
||||
_PyPegen_get_expr_name(a)
|
||||
)}
|
||||
|
||||
invalid_block:
|
||||
| NEWLINE !INDENT { RAISE_INDENTATION_ERROR("expected an indented block") }
|
||||
invalid_comprehension:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue