[Python-ideas] PEP 505 (None coalescing operators) thoughts
Sven R. Kunze
srkunze at mail.de
Mon Sep 28 18:47:05 CEST 2015
On 28.09.2015 18:37, Steven D'Aprano wrote:
> On Mon, Sep 28, 2015 at 06:11:45PM +0200, Sven R. Kunze wrote:
>> That sums it all up for me as well, though I would rather use "else"
>> instead of "or?" (see punctuation-heavy).
> `else` is ambiguous. Consider:
> result = spam if eggs else cheese else aardvark
> could be interpreted three ways:
> result = (spam if eggs else cheese) else aardvark
> result = spam if (eggs else cheese) else aardvark
> result = spam if eggs else (cheese else aardvark)
> Whichever precedence you pick, some people will get it wrong and it will
> silently do the wrong thing and lead to hard-to-diagnose bugs. Using
> "else" for this will be a bug-magnet.
I wouldn't make a mountain out of a molehill. Other existing operators
have the same issue.
More information about the Python-ideas