[Python-Dev] Adding a conditional expression in Py3.0

Terry Reedy tjreedy at udel.edu
Tue Sep 20 21:00:41 CEST 2005

"Guido van Rossum" <guido at python.org> wrote in message 
news:ca471dc2050920090461aec3da at mail.gmail.com...
> In fact, I think Raymond's example is more properly considered an
> argument for adding a conditional expression than for removing the
> current behavior of the and/or shortcut operators; had we had a
> conditional expression, he wouldn't have tried to use the "x and y or
> z" syntax that bit him.

I agree.

> Given this realization, I'm now -1 on Raymond's idea,

There are a lot of people who use 'or', especially, as intended.

> and +1 on adding a conditional expression. I believe (y if x else z)
> was my favorite last time, wasn't it?

No.  That was your original proposal, which you later rejected.

"The original version of this PEP proposed the following syntax:
        <expression1> if <condition> else <expression2>
    The out-of-order arrangement was found to be too uncomfortable
    for many of participants in the discussion; especially when
    <expression1> is long, it's easy to miss the conditional while

Your final 'favorite' was apparently (at the top)

    The proposed syntax is as follows:
    (if <condition>: <expression1> else: <expression2>) " (+ elif parts)

selected from

"Summary of the Current State of the Discussion
   Groups are falling into one of three camps:
    1.  Adopt a ternary operator built using punctuation characters:
            <condition> ? <expression1> : <expression2>
    2.  Adopt a ternary operator built using new or existing keywords.
        The leading examples are:
            <condition> then <expression1> else <expression2>
            (if <condition>: <expression1> else: <expression2>)
    3.  Do nothing."

Given the later addition of generator expressions with mandatory 
parentheses , the mandatory-parentheses version of a conditional expression 
looks less strange to me than it did then ;-).  So I could happily use it 
even though I may still lean toward the other option 2 version (then-else) 
due to  its not needing ':'s or a third elseif term for chaining.

*If* you want general community input, I would suggest a runoff ballot with 
those four choices (and a summary of pros and cons of each), or fewer if 
you see any as unacceptible.

Terry J. Reedy

> -- 
> --Guido van Rossum (home page: http://www.python.org/~guido/)
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: 
> http://mail.python.org/mailman/options/python-dev/python-python-dev%40m.gmane.org

More information about the Python-Dev mailing list