[Python-Dev] more pyref: continue in finally statements
"Martin v. Löwis"
martin at v.loewis.de
Mon May 1 21:09:36 CEST 2006
Fredrik Lundh wrote:
> the language reference says:
>
> continue may only occur syntactically nested in a for or while loop,
> but not nested in a function or class definition or finally statement
> within that loop. /.../
>
> It may occur within an except or else clause. The restriction on occurring
> in the try clause is implementor's laziness and will eventually be lifted.
>
> and it looks like the new compiler still has the same issue:
>
> $ python test.py
> File "test.py", line 5:
> continue
> SyntaxError: 'continue' not supported inside 'finally' clause
>
> how hard would it be to fix this ?
>
> (shouldn't the "try clause" in the note read "finally clause", btw? "continue"
> within the "try" suite seem to work just fine...)
For the latter: the documentation apparently wasn't fully updated in
r19260: it only changed ref7.tex, but not ref6.tex. IOW, it really
means to say "in the try clause", and it is out-of-date in saying so.
As for "continue in the 'finally' clause: What would that mean?
Given
def f():
raise Exception
while 1:
try:
f()
finally:
g()
continue
then what should be the meaning of "continue" here? The finally
block *eventually* needs to re-raise the exception. When should
that happen?
So I would say: It's very easy to fix, just change the message to
SyntaxError: 'continue' not allowed inside 'finally' clause
:-)
Regards,
Martin
More information about the Python-Dev
mailing list