[Python-ideas] except expression

Alexander Belopolsky alexander.belopolsky at gmail.com
Tue Feb 18 18:01:29 CET 2014


On Tue, Feb 18, 2014 at 11:25 AM, Paul Moore <p.f.moore at gmail.com> wrote:

> On 18 February 2014 15:51, Chris Angelico <rosuav at gmail.com> wrote:
> > On Wed, Feb 19, 2014 at 2:41 AM, Alexander Belopolsky
> > <alexander.belopolsky at gmail.com> wrote:
> >> I would not mind
> >>
> >>  x = 1/f(y) except 0
> >>
> >> not catching a TypeError that may come from f(y) in most cases.
> >
> > But should it catch a KeyError from inside f(y), based on the
> > translation of d.get()?
>
> Explicit is better than implicit - I think this discussion has done
> its job and established that trying to assume a subset of exceptions
> to catch isn't going to work. We either allow a bare except to mean
> "catch all exceptions" (which exactly the same risks and provisos as a
> bare except *statement*) or we make the exception to catch mandatory.


I disagree.  It is best to leave explicit selection of exceptions to catch
outside of the expressions.  This is job for things like decimal or numpy
fp contexts.

Always requiring a long camel-case name inside an expression will kill most
of the advantages.

For example, it would be nice to be able to write something like

x = d1[key] except d2[key] except 0

but sprinkle this with repeated KeyError and what is important (d1 and d2)
will be lost in the scaffolding.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140218/ad8f85a2/attachment.html>


More information about the Python-ideas mailing list