summaryrefslogtreecommitdiffstats
path: root/Grammar/python.gram
diff options
context:
space:
mode:
authorMiguel Brito <5544985+miguendes@users.noreply.github.com>2021-08-02 17:11:37 (GMT)
committerGitHub <noreply@github.com>2021-08-02 17:11:37 (GMT)
commit28b6dc9dd5d1ce6f8aff7e06d4ef9afdc2bc8332 (patch)
tree7588a22ecc75a5ea73476644d56dbc9d0fd8659e /Grammar/python.gram
parentaa0894b3792901adb91e5f6d049154b7bcb980ec (diff)
downloadcpython-28b6dc9dd5d1ce6f8aff7e06d4ef9afdc2bc8332.zip
cpython-28b6dc9dd5d1ce6f8aff7e06d4ef9afdc2bc8332.tar.gz
cpython-28b6dc9dd5d1ce6f8aff7e06d4ef9afdc2bc8332.tar.bz2
bpo-44792: Improve syntax errors for if expressions (GH-27506)
Diffstat (limited to 'Grammar/python.gram')
-rw-r--r--Grammar/python.gram1
1 files changed, 1 insertions, 0 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram
index 8a21056..91d8a69 100644
--- a/Grammar/python.gram
+++ b/Grammar/python.gram
@@ -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 {