Skip to content

Commit 62996a0

Browse files
author
Steele Farnsworth
committed
Test for special syntax error for elif following else
1 parent 4b53bf3 commit 62996a0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Lib/test/test_syntax.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,18 @@
918918
...
919919
SyntaxError: 'break' outside loop
920920
921+
elif can't come after an else.
922+
923+
>>> if a % 2 == 0:
924+
... pass
925+
... else:
926+
... pass
927+
... elif a % 2 == 1:
928+
... pass
929+
Traceback (most recent call last):
930+
...
931+
SyntaxError: 'elif' block follows an 'else' block
932+
921933
Misuse of the nonlocal and global statement can lead to a few unique syntax errors.
922934
923935
>>> def f():

0 commit comments

Comments
 (0)