[Python-ideas] Make return inside a finally a SyntaxError
Stephen J. Turnbull
stephen at xemacs.org
Sat Jul 18 07:17:05 CEST 2009
Greg Ewing writes:
> Michael wrote:
> > Here are two examples of why allowing return inside a finally block is
> > a bad idea:
>
> Don't do those things, then!
>
> Nobody is *forcing* you to write returns inside
> finally blocks.
+1
Why not just emphasize in the documentation that return (etc) in a
finally: suite *will* get executed *after* return or an exception is
raised in the try: suite? "These stunts were performed by
professionals. Don't try this at home, kids."
More specifically, maybe there should be an explicit warning that in a
finally: suite
if exit_condition:
return
do_work()
# end of suite
has (perhaps surprisingly, YMMV) different semantics from
if not exit_condition:
do_work()
# end of suite
WDOT?
More information about the Python-ideas
mailing list