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

Donald Stufft donald at stufft.io
Mon Sep 28 18:40:51 CEST 2015


could use two words!

result = spam or else eggs

On September 28, 2015 at 12:38:21 PM, Steven D'Aprano (steve at pearwood.info) 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.
> 
> 
> 
> --
> Steve
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
> 

-----------------
Donald Stufft
PGP: 0x6E3CBCE93372DCFA // 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA




More information about the Python-ideas mailing list