summaryrefslogtreecommitdiff
path: root/Lib/test/test_syntax.py
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-08-21 19:47:08 +0000
committerNeal Norwitz <nnorwitz@gmail.com>2006-08-21 19:47:08 +0000
commit4f096d948797cabbe717197faf4d979d68badd0b (patch)
treeecba29cf8fafc590b7a3fb8cfa1f6a911534d3da /Lib/test/test_syntax.py
parent076d1e0c0b1858a9086c63c237cbe13691231b0f (diff)
downloadcpython-git-4f096d948797cabbe717197faf4d979d68badd0b.tar.gz
Patch #1542451: disallow continue anywhere under a finally
I'm undecided if this should be backported to 2.5 or 2.5.1. Armin suggested to wait (I'm of the same opinion). Thomas W thinks it's fine to go in 2.5.
Diffstat (limited to 'Lib/test/test_syntax.py')
-rw-r--r--Lib/test/test_syntax.py87
1 files changed, 87 insertions, 0 deletions
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index dc7a16d1e2..692ba57a3e 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -235,6 +235,93 @@ SyntaxError: assignment to None (<doctest test.test_syntax[32]>, line 1)
>>> f() += 1
Traceback (most recent call last):
SyntaxError: illegal expression for augmented assignment (<doctest test.test_syntax[33]>, line 1)
+
+
+Test continue in finally in weird combinations.
+
+continue in for loop under finally shouuld be ok.
+
+ >>> def test():
+ ... try:
+ ... pass
+ ... finally:
+ ... for abc in range(10):
+ ... continue
+ ... print abc
+ >>> test()
+ 9
+
+Start simple, a continue in a finally should not be allowed.
+
+ >>> def test():
+ ... for abc in range(10):
+ ... try:
+ ... pass
+ ... finally:
+ ... continue
+ Traceback (most recent call last):
+ ...
+ SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[36]>, line 6)
+
+This is essentially a continue in a finally which should not be allowed.
+
+ >>> def test():
+ ... for abc in range(10):
+ ... try:
+ ... pass
+ ... finally:
+ ... try:
+ ... continue
+ ... except:
+ ... pass
+ Traceback (most recent call last):
+ ...
+ SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[37]>, line 7)
+
+ >>> def foo():
+ ... try:
+ ... pass
+ ... finally:
+ ... continue
+ Traceback (most recent call last):
+ ...
+ SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[38]>, line 5)
+
+ >>> def foo():
+ ... for a in ():
+ ... try:
+ ... pass
+ ... finally:
+ ... continue
+ Traceback (most recent call last):
+ ...
+ SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[39]>, line 6)
+
+ >>> def foo():
+ ... for a in ():
+ ... try:
+ ... pass
+ ... finally:
+ ... try:
+ ... continue
+ ... finally:
+ ... pass
+ Traceback (most recent call last):
+ ...
+ SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[40]>, line 7)
+
+ >>> def foo():
+ ... for a in ():
+ ... try: pass
+ ... finally:
+ ... try:
+ ... pass
+ ... except:
+ ... continue
+ Traceback (most recent call last):
+ ...
+ SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[41]>, line 8)
+
"""
import re