[Python-ideas] Potential PEP: with/except

Adrien Ricocotam ricocotam at gmail.com
Wed Jan 23 16:20:02 EST 2019


I have a neutral feeling about the proposal but I’d like to suggest
something

We can extend the try/with to other blocks, as suggested. What could be
done to prevent any ambiguity is :

try with blabla as blabla2 :
    ...
except:
    ...

Which is equivalent  of :
try:
    with blabla as blabl2:
        ...
except:
    ....

Any other combination should be explicit, except if there’s a nice syntax
but I didn’t find it.

Extending to other blocks would give :

try for ... in ...:
    ...
except:
    ...

But if we use the « else » here, what’s going on ? It’s a one line saver
(which is useless) but having many indented blocks doesn’t produce readable
code in my opinion. Saving one indented block while keeping things clear is
a good thing in my opinion. As long as it stays clear (which is not the
case in the for block).

But adding this feature to the with block without using it for other blocks
is a bit strange, imho.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190123/a9adfd80/attachment.html>


More information about the Python-ideas mailing list