Skip to content

Commit 883ada9

Browse files
committed
Special syntax error for elif block after else
Previously, having an elif block after an else block would raise a standard syntax error.
1 parent a29a9c0 commit 883ada9

File tree

2 files changed

+107
-73
lines changed

2 files changed

+107
-73
lines changed

Grammar/python.gram

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,7 @@ invalid_elif_stmt:
13961396
invalid_else_stmt:
13971397
| a='else' ':' NEWLINE !INDENT {
13981398
RAISE_INDENTATION_ERROR("expected an indented block after 'else' statement on line %d", a->lineno) }
1399+
| 'else' ':' block 'elif' { RAISE_SYNTAX_ERROR("elif not allowed after else")}
13991400
invalid_while_stmt:
14001401
| 'while' named_expression NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
14011402
| a='while' named_expression ':' NEWLINE !INDENT {

0 commit comments

Comments
 (0)