mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-32489: Allow 'continue' in 'finally' clause. (GH-5822)
This commit is contained in:
parent
134cb01cda
commit
fe2bbb1869
10 changed files with 97 additions and 70 deletions
|
@ -298,7 +298,7 @@ continue in for loop under finally should be ok.
|
|||
>>> test()
|
||||
9
|
||||
|
||||
Start simple, a continue in a finally should not be allowed.
|
||||
continue in a finally should be ok.
|
||||
|
||||
>>> def test():
|
||||
... for abc in range(10):
|
||||
|
@ -306,11 +306,9 @@ Start simple, a continue in a finally should not be allowed.
|
|||
... pass
|
||||
... finally:
|
||||
... continue
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
SyntaxError: 'continue' not supported inside 'finally' clause
|
||||
|
||||
This is essentially a continue in a finally which should not be allowed.
|
||||
... print(abc)
|
||||
>>> test()
|
||||
9
|
||||
|
||||
>>> def test():
|
||||
... for abc in range(10):
|
||||
|
@ -321,9 +319,24 @@ This is essentially a continue in a finally which should not be allowed.
|
|||
... continue
|
||||
... except:
|
||||
... pass
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
SyntaxError: 'continue' not supported inside 'finally' clause
|
||||
... print(abc)
|
||||
>>> test()
|
||||
9
|
||||
|
||||
>>> def test():
|
||||
... for abc in range(10):
|
||||
... try:
|
||||
... pass
|
||||
... finally:
|
||||
... try:
|
||||
... pass
|
||||
... except:
|
||||
... continue
|
||||
... print(abc)
|
||||
>>> test()
|
||||
9
|
||||
|
||||
A continue outside loop should not be allowed.
|
||||
|
||||
>>> def foo():
|
||||
... try:
|
||||
|
@ -332,42 +345,7 @@ This is essentially a continue in a finally which should not be allowed.
|
|||
... continue
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
SyntaxError: 'continue' not supported inside 'finally' clause
|
||||
|
||||
>>> def foo():
|
||||
... for a in ():
|
||||
... try:
|
||||
... pass
|
||||
... finally:
|
||||
... continue
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
SyntaxError: 'continue' not supported inside 'finally' clause
|
||||
|
||||
>>> def foo():
|
||||
... for a in ():
|
||||
... try:
|
||||
... pass
|
||||
... finally:
|
||||
... try:
|
||||
... continue
|
||||
... finally:
|
||||
... pass
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
SyntaxError: 'continue' not supported inside 'finally' clause
|
||||
|
||||
>>> def foo():
|
||||
... for a in ():
|
||||
... try: pass
|
||||
... finally:
|
||||
... try:
|
||||
... pass
|
||||
... except:
|
||||
... continue
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
SyntaxError: 'continue' not supported inside 'finally' clause
|
||||
SyntaxError: 'continue' not properly in loop
|
||||
|
||||
There is one test for a break that is not in a loop. The compiler
|
||||
uses a single data structure to keep track of try-finally and loops,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue