aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_syntax.py
diff options
context:
space:
mode:
authorSteele Farnsworth <swfarnsworth@gmail.com>2025-04-24 21:25:48 -0400
committerGitHub <noreply@github.com>2025-04-25 01:25:48 +0000
commit99b71efe8e9d59ce04b6d59ed166b57dff3e84d8 (patch)
tree13b4dd6d9e08f44c86261116667954672a103df6 /Lib/test/test_syntax.py
parentc3a71180656a906d243e4cc0ab974387753b2fe1 (diff)
downloadcpython-99b71efe8e9d59ce04b6d59ed166b57dff3e84d8.tar.gz
cpython-99b71efe8e9d59ce04b6d59ed166b57dff3e84d8.zip
gh-129858: Special syntax error for `elif` block after `else` (#129902)
Diffstat (limited to 'Lib/test/test_syntax.py')
-rw-r--r--Lib/test/test_syntax.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index 8cae62459bb..4c001f9c9b0 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -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():