gh-129858: Special syntax error for elif block after else (#129902)

This commit is contained in:
Steele Farnsworth 2025-04-24 21:25:48 -04:00 committed by GitHub
parent c3a7118065
commit 99b71efe8e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 137 additions and 75 deletions

View file

@ -948,6 +948,18 @@ isn't, there should be a syntax error.
...
SyntaxError: 'break' outside loop
elif can't come after an else.
>>> if a % 2 == 0:
... pass
... else:
... pass
... elif a % 2 == 1:
... pass
Traceback (most recent call last):
...
SyntaxError: 'elif' block follows an 'else' block
Misuse of the nonlocal and global statement can lead to a few unique syntax errors.
>>> def f():