diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2020-05-15 01:04:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-15 01:04:52 (GMT) |
commit | 16ab07063cb564c1937714bd39d6915172f005b5 (patch) | |
tree | f536d329aa196ac4755d3407a698dae48f9bb7b5 /Grammar | |
parent | 7ba1f75f3f02b4b50ac6d7e17d15e467afa36aac (diff) | |
download | cpython-16ab07063cb564c1937714bd39d6915172f005b5.zip cpython-16ab07063cb564c1937714bd39d6915172f005b5.tar.gz cpython-16ab07063cb564c1937714bd39d6915172f005b5.tar.bz2 |
bpo-40334: Correctly identify invalid target in assignment errors (GH-20076)
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Diffstat (limited to 'Grammar')
-rw-r--r-- | Grammar/python.gram | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram index 9087c7a..cca9209 100644 --- a/Grammar/python.gram +++ b/Grammar/python.gram @@ -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: |