mirror of
https://github.com/python/cpython.git
synced 2025-08-02 08:02:56 +00:00
bpo-44792: Improve syntax errors for if expressions (GH-27506)
This commit is contained in:
parent
aa0894b379
commit
28b6dc9dd5
5 changed files with 48 additions and 0 deletions
|
@ -1083,6 +1083,7 @@ invalid_expression:
|
|||
# Soft keywords need to also be ignored because they can be parsed as NAME NAME
|
||||
| !(NAME STRING | SOFT_KEYWORD) a=disjunction b=expression_without_invalid {
|
||||
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Perhaps you forgot a comma?") }
|
||||
| a=disjunction 'if' b=disjunction !'else' { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "expected 'else' after 'if' expression") }
|
||||
|
||||
invalid_named_expression:
|
||||
| a=expression ':=' expression {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue