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

Guido van Rossum guido at python.org
Thu Jan 4 20:24:56 EST 2018


We should interview you for the paper we may be writing for HOPL.

On Wed, Jan 3, 2018 at 6:05 PM, Neil Schemenauer <nas-python at arctrix.com>
wrote:

> On 2018-01-03, Guido van Rossum wrote:
> > I'm sorry, I don't think more research can convince me either way.
> > I want all three of return/break/continue to work inside finally
> > clauses, despite there being few use cases.
>
> That's fine.  The history of 'continue' inside 'finally' is
> interesting.  The restriction dates back to at least when Jeremy
> committed the AST-based compiler (I have fond memories of hacking on
> it with Armin Rigo and others at a Python core sprint).  Going
> further back, I looked at 1.5.2 and there is the comment in
> compile.c:
>
>     TO DO:
>     ...
>     XXX Allow 'continue' inside try-finally
>
> So if we allow 'continue' we will be knocking off a nearly 20 year
> old todo item. ;-)
>
> For giggles, I unpacked a Python 0.9.1 tarball.  The source code is
> all under 'src' in that version.  There doesn't seem to be a
> restriction on 'continue' but only because the grammar doesn't
> include it!  Without doing more research, I think the restriction
> could be as old as the 'continue' keyword.
>
> BTW, the bytecode structure for try/except shown in the compile.c
> comments is very simlar to what is currently generated.  It is quite
> remarkable how well your initial design and implementation have stood
> the test of time.  Thank you for making it open source.
>
> Regards,
>
>   Neil
>



-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20180104/2760f5ff/attachment.html>


More information about the Python-Dev mailing list