[Python-ideas] Make return inside a finally a SyntaxError
Christian Heimes
lists at cheimes.de
Sat Jul 18 02:31:13 CEST 2009
Michael schrieb:
> 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
>
Woot! That's totally. It never even occurred to me to use return in the
finally block. +1 for the syntax error. Nice catch, Michael!
Christian
PS: I wasn't sure so I tested the functions. Both functions return 4.
More information about the Python-ideas
mailing list