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

Curt Hagenlocher curt at hagenlocher.org
Sat Jul 18 05:04:42 CEST 2009


On Fri, Jul 17, 2009 at 7:13 PM, Guido van Rossum <guido at python.org> wrote:
>
> Since you agree that an exception raised in a finally block has
> well-defined semantics, why wouldn't a return statement?

Because I'm not always fortunate enough to be programming in Python,
and I don't use any other language where "return" can swallow
exceptions.

I see how this behavior is internally consistent and even potentially
useful. But as a reader of code, I've got internal models of the
semantics of both "finally" and "return", and because I associate
"finally" with exceptional circumstances, my model for "finally"
activates more strongly in this case than my model for "return".
Ultimately, it has an adverse effect on my ability to reason about the
code.

On the other hand, even if I was certain this was a design error, I
wouldn't feel it was worth losing backward compatibility over.

--
Curt Hagenlocher
curt at hagenlocher.org



More information about the Python-ideas mailing list