[Python-ideas] except expression

Amber Yust amber.yust at gmail.com
Thu Feb 13 06:53:39 CET 2014


That has a potential conflict in parsing, however, since the if-else
ternary already exists. Yes, the 'as' theoretically disambiguates it for
the machine parser, but for a human trying to parse it as they read, it's
not nearly as simple.

The reason why I suggested 'for' is that it still flows somewhat naturally
- it's using "for" in the sense of "associated with" or "in the place of".
"I'll give you my None for your FooException."

On Wed Feb 12 2014 at 9:46:37 PM, Antony Lee <antony.lee at berkeley.edu>
wrote:

> Even more generally (not sure allowing multiple clauses is a good idea but
> at least "if" sounds better than "for", I think.
> foo = bar() except e.attr1 if FooException as e else e.attr2 if
> BarException as e
>
> Antony Lee
>
>
> 2014-02-12 19:25 GMT-08:00 Amber Yust <amber.yust at gmail.com>:
>
> Another possible option:
>
> foo = something() except None for BarException
>
> With possible support for:
>
> foo = something() except e.message for BarException as e
> On Feb 12, 2014 7:20 PM, "Amber Yust" <amber.yust at gmail.com> wrote:
>
> Ah, that's a good point (the two-directionality of yield had slipped my
> mind). I had considered suggesting return instead of yield, which wouldn't
> have that problem, but it felt like return would be more confusing to see
> in a context where it doesn't actually return from the enclosing scope.
> On Feb 12, 2014 7:16 PM, "Chris Angelico" <rosuav at gmail.com> wrote:
>
> On Thu, Feb 13, 2014 at 2:08 PM, Amber Yust <amber.yust at gmail.com> wrote:
> > Why not use yield instead of else?
> >
> > foo = something() except BazException yield "bar"
>
> yield is already an expression. It'd be theoretically and
> syntactically valid (if a little weird) to use yield "bar" in place of
> the name BazException; you'd yield "bar" to your caller, then whatever
> exception gets sent in would be the one tested for. I honestly cannot
> conceive of any situation where this would actually be useful, but it
> does make it a little tricky to reuse that keyword :)
>
> 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/
>
>
> _______________________________________________
> 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/20140213/eef3c1e9/attachment.html>


More information about the Python-ideas mailing list