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

Steven D'Aprano steve at pearwood.info
Mon Sep 28 18:37:33 CEST 2015


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.



-- 
Steve


More information about the Python-ideas mailing list