[Python-ideas] if we were to ever shorten `A if A else B` (was: PEP 505: None-aware operators)

Brett Cannon brett at python.org
Fri Jul 20 20:29:37 EDT 2018

On Thu, 19 Jul 2018 at 14:29 Steve Dower <steve.dower at python.org> wrote:

> [SNIP]
> * "We could have 'else', we don't need '??'"
> This is the "a else 'default'" rather than "a ?? 'default'" proposal,
> which I do like the look of, but I think it will simultaneously mess
> with operator precedence and also force me to search for the 'if' that
> we actually need to be comparing "(a else 'default')" vs. "a ??
> 'default'"::
>      x = a if b else c else d
>      x = a if (b else c) else d
>      x = a if b else (c else d)

The searching for the 'if' also throws me with this proposal. I think
someone else proposed `A unless B` but I always prefer knowing upfront what
I'm working with, not later by having to read farther along.

Personally, if the `A?? B` is the part people like but hate the syntax then
my vote would go to `A otherwise B` since it's unambiguous, the case you
care about the state  of comes first, and it doesn't trip your brain up
looking for 'if'. :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180720/389381f0/attachment.html>

More information about the Python-ideas mailing list