[Python-ideas] except expression

David Mertz mertz at gnosis.cx
Wed Feb 19 10:04:54 CET 2014


I don't know if this really amounts to a *strong* objection.  To me, as
much as I try to like it reading this thread, the colon just continues to
feel wrong to me.  Yes, of course I know the analogy with lambda, and I can
even see a certain analogy with dict literals.  However, far more
compelling to me is making it look more like the ternary expression (which
it is really basically a special case of.

In terms of keywords to put in place of the colon, the "least bad" in my
mind is "return."  Yes, of course, we don't actually return out of a
function call or remove a call stack element (well, unless we wind up doing
so in the implementation).  But without fuzzing one's brain *too much* one
can think of the except expression as kind of like a function call, and
though of that way, 'return' makes sense.

The next "least bad" in my mind is 'else' because if preserved the parallel
with 'val if cond else fallback' most closely.  Sure, we need a bit more
verbosity in the expression, especially when 'as' is used (and it should be
included), i.e.:

  x = val except SomeError as e else something(e)

But still it's basically only substituting the one 'if' for an 'except' and
otherwise keeping the familiar ternary expression.

Of course, my opinion here is of very slight value, since the intuitions of
our BDFL will decide the outcome, and the various alternatives are present
in the PEP.  And indeed, if the colon is what "wins", I'll learn to use it
and be more comfortable with it.



On Wed, Feb 19, 2014 at 12:17 AM, Chris Angelico <rosuav at gmail.com> wrote:

> On Wed, Feb 19, 2014 at 6:53 PM, Paul Moore <p.f.moore at gmail.com> wrote:
> > So having struggled to find objections to the colon syntax, I've
> > reached a point where I think it's the best of the alternatives. "I
> > can't find a good enough objection" isn't exactly a ringing
> > endorsement, but it's the best I've got :-)
>
> Hehe. That's one way to settle it!
>
> If anyone does have a strong objection, I do want to hear. Sometimes a
> thread like this starts piling off in one direction, and any voice
> going the other way may feel like yelling into a hurricane, but a lot
> of the decisions made in the PEP have been on a fairly light balance
> of evidence. One good shout in a different direction could change some
> of them. The 'as' clause is currently hanging in the balance, for
> instance:
>
> Pro: Consistency with try/except statement, functionality.
>
> Con: Introduces complexity, functionality isn't used.
>
> It's on the knife-edge. Currently it's in, but could go out more
> easily than a Pommie batsman.
>
> *dives for cover*
>
> 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/
>



-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140219/5bd9b268/attachment.html>


More information about the Python-ideas mailing list