[Python-ideas] except expression

אלעזר elazarg at gmail.com
Wed Feb 19 14:00:55 CET 2014


A bit OT:
I think there should be a mention in the PEP of other languages with
exception-handling expressions, like SML's

    - (hd []) handle Empty => 1;
    val it = 1 : int

Which reminds Nick's proposal. I think the parens makes it look very clean
in such simple examples.

---
Elazar


2014-02-19 14:47 GMT+02:00 Chris Angelico <rosuav at gmail.com>:

> On Wed, Feb 19, 2014 at 11:17 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> > Right, unless Guido manages to pull another PEP 308 style "I have come
> > up with a clever idea nobody else thought of, and likely only the BDFL
> > could sell to anyone else", I think the colon based version Chris has
> > written up in the PEP currently counts as "least bad of the
> > alternatives proposed, and sufficiently tolerable to be judged better
> > than the assortment of relatively ad hoc workarounds we have at the
> > moment".
> >
> > That said, I did suggest using the function return type annotation
> > marker as a possibility, and that's not currently listed in the PEP:
> >
> >     value = lst[2] except IndexError -> 'No value'
>
> I missed that in the flurry. Have added it now.
>
> > On an unrelated tangent (as I forget which part of the thread it came
> > up in), having to switch from the compiler checked and code completion
> > friendly 'obj.attr' to the more opaque (from an automated code
> > analysis point of view) 'getattr(obj, "attr", None)' is another
> > symptom of this current limitation that should be listed in the
> > motivation section of the PEP.
>
> Good point. Also added, though I put it into Rationale rather than
> Motivation.
>
> ChrisA
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140219/d17ec791/attachment-0001.html>


More information about the Python-ideas mailing list