diff options
author | 2020-05-15 02:04:52 +0100 | |
---|---|---|
committer | 2020-05-15 02:04:52 +0100 | |
commit | 16ab07063cb564c1937714bd39d6915172f005b5 (patch) | |
tree | f536d329aa196ac4755d3407a698dae48f9bb7b5 /Grammar | |
parent | bpo-38872: Document exec symbol for codeop.compile_command (GH-20047) (diff) | |
download | cpython-16ab07063cb564c1937714bd39d6915172f005b5.tar.gz cpython-16ab07063cb564c1937714bd39d6915172f005b5.tar.bz2 cpython-16ab07063cb564c1937714bd39d6915172f005b5.zip |
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 9087c7aa718..cca92090546 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: |