On Wed, Jul 15, 2020 at 05:45:05AM +0000, Steve Barnes wrote:

> Can I suggest that for loops the `else` would be a lot clearer if it 
> was spelt `finally` as was done for PEP-0341 for try blocks and that 
> we might possibly need one or more `on_…` clauses such as `on_break` 
> and `on_finish` I think that this would be a lot clearer:

Sorry Steve, "finally" would be a terrible name because it behaves 
nothing like try...finally. In try blocks, the finally block is *always* 
executed, even if you raise, even if you return.

(To be precise, there are odd and unusual cases where finally won't be 
executed, such as if the interpreter process is `kill -9`'ed, or if a 
power surge fries the CPU. But under normal processing, finally always 
runs.)

But the for...finally (renamed from for...else) is not like that. If 
anything, it's the opposite of finally: it is a block designed to be 
skipped, not a block designed to always run.

Any of `break`, `return` or `raise` will cause the for...finally clause 
to be skipped. So we would be swapping one form of confusion to another 
("why is my finally clause not executed?").



-- 
Steven
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/UGNODYQOAWKS5QRYG352YUW6DLJEDGUP/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to