summaryrefslogtreecommitdiffstats
path: root/Grammar
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2022-11-20 18:29:05 (GMT)
committerGitHub <noreply@github.com>2022-11-20 18:29:05 (GMT)
commit152a437b8dee77fe10f13f504da3ee63f1dd3657 (patch)
tree9164d6b84f9657cba22a2b649fa667d753d11f8a /Grammar
parent56a517e9e854559e2f0c23c0e5adcaf846a2e0c3 (diff)
downloadcpython-152a437b8dee77fe10f13f504da3ee63f1dd3657.zip
cpython-152a437b8dee77fe10f13f504da3ee63f1dd3657.tar.gz
cpython-152a437b8dee77fe10f13f504da3ee63f1dd3657.tar.bz2
[3.11] gh-99211: Point to except/except* on syntax errors when mixing them (GH-99215) (GH-99622)
gh-99211: Point to except/except* on syntax errors when mixing them (GH-99215) (cherry picked from commit 9c4232ae8972a33f84e875cfdd866318a1233e47)
Diffstat (limited to 'Grammar')
-rw-r--r--Grammar/python.gram4
1 files changed, 3 insertions, 1 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram
index e32008c..bae8bc3 100644
--- a/Grammar/python.gram
+++ b/Grammar/python.gram
@@ -1247,7 +1247,9 @@ invalid_try_stmt:
| a='try' ':' NEWLINE !INDENT {
RAISE_INDENTATION_ERROR("expected an indented block after 'try' statement on line %d", a->lineno) }
| 'try' ':' block !('except' | 'finally') { RAISE_SYNTAX_ERROR("expected 'except' or 'finally' block") }
- | a='try' ':' block* ((except_block+ except_star_block) | (except_star_block+ except_block)) block* {
+ | 'try' ':' block* except_block+ a='except' b='*' expression ['as' NAME] ':' {
+ RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "cannot have both 'except' and 'except*' on the same 'try'") }
+ | 'try' ':' block* except_star_block+ a='except' [expression ['as' NAME]] ':' {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot have both 'except' and 'except*' on the same 'try'") }
invalid_except_stmt:
| 'except' '*'? a=expression ',' expressions ['as' NAME ] ':' {