[Python-Dev] PEP 463: Exception-catching expressions

Glenn Linderman v+python at g.nevcal.com
Sat Mar 1 02:24:22 CET 2014


On 2/28/2014 4:51 AM, Nick Coghlan wrote:
> The preferred notation in the PEP most resembles the existing lambda
> use case, with "except" instead of "lambda", an exception handling
> spec instead of an argument list and an additional leading expression:
>
>      (expr except Exception: default)
>
> Lots of people don't like the lambda notation though, so it isn't
> necessarily a particularly compelling parallel to use.

Thank you for explaining why I find the above notation awkward.  ": as 
introducing a suite" never bothered me, because, as you've now 
enumerated, there are other uses of :.

But the lambda syntax parallel is what I don't like about it... I find 
the lambda syntax hard to read.

> By contrast,
> it's rare to hear any objections to the {key:value} dict display
> syntax. Hence the proposed tweak to the syntax to define an "exception
> handler expression" syntax that is analogous to a dict display rather
> than a lambda expression:
>
>      expr except (Exception: default)
>
> However, I have realised that there*is*  a major downside to that
> notation, which is that it lacks the connotations of lazy evaluation
> associated with lambda expressions, whereas the default result of an
> except expression won't be evaluated at all if the exception isn't
> thrown.
You are overlooking that the keyword except provides exactly the 
connotation of lazy evaluation, so if this is your only reason for 
preferring the lambda syntax, you just erased it :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140228/777241c1/attachment.html>


More information about the Python-Dev mailing list