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

Calvin Spealman ironfroggy at gmail.com
Sat Jul 18 14:52:47 CEST 2009


I honestly can't read those examples and be surprised. Do I have
finally-colored glasses? Maybe "What does f do? It returns 3, but then
in finally returns 4" reads understandably, if silly, to me.

I will admit that a finally with a non-conditional return or raise
will effectively be a blank except: but in that case, as well, I say
"well, don't do that"

On Fri, Jul 17, 2009 at 7:41 PM, Michael<fuzzyman at gmail.com> 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
>
>
> Michael Foord
>
> --
> http://www.ironpythoninaction.com
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>



-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://techblog.ironfroggy.com/
Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy



More information about the Python-ideas mailing list