[Python-Dev] 'continue'/'break'/'return' inside 'finally' clause

Neil Schemenauer nas-python at arctrix.com
Wed Jan 3 02:53:42 EST 2018


Generally I think programming language implementers don't get to
decide how the language works. You just have to implement it as
specified, inconvenient as that might be.

However, from a languge design prespective, I think there is a good
argument that this is a corner of the language we should consider
changing.  First, I analyzed over one million lines of Python code
with my AST walker and only found this construct being used in four
different places.  It seems to be extremely rare.

Second, the existance of a pylint warning for it suggests that it is
confusing. I did a little more searching using the pylint warning
and found these pages:

    https://stackoverflow.com/questions/35505624/break-statement-in-finally-block-swallows-exception
    http://thegreyblog.blogspot.ca/2011/02/do-not-return-in-finally-block-return.html

So, given the above and that the implementation (both compiler and
bytecode evaluator) is pretty complicated, I vote that we should
disallow it.

Regards,

  Neil


More information about the Python-Dev mailing list