[Python-ideas] Make return inside a finally a SyntaxError

MRAB python at mrabarnett.plus.com
Sat Jul 18 02:18:36 CEST 2009


Michael wrote:
> Here are two examples of why allowing return inside a finally block is a 
> bad idea:
> 
> def f():
>   try:
>     return 3
>   finally:
>     return 4
> 
> def f():
>   try:
>     raise Exception()
>   finally:
>     return 4
> 
I wouldn't call that a syntax error. Wouldn't you also have to forbid 
break, continue and, perhaps, yield?

Isn't Python for consenting adults, or something like that? :-)



More information about the Python-ideas mailing list