[Python-ideas] PEP 505 (None coalescing operators) thoughts

Sven R. Kunze srkunze at mail.de
Mon Sep 28 21:47:10 CEST 2015


On 28.09.2015 19:24, Andrew Barnert wrote:
> On Sep 28, 2015, at 09:47, Sven R. Kunze <srkunze at mail.de> wrote:
>>
>>>      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.
> Which other keywords or symbols may be either a binary operator or part of a ternary operator depending on context?

It has nothing to do with either of it.

I've seen young students struggling with the op precedence of AND and 
OR; and I've seen experienced coworkers rather adding superfluous pairs 
of parentheses just to make sure or because they still don't know better.

Best,
Sven


More information about the Python-ideas mailing list