[Python-ideas] Null coalescing operators

Chris Angelico rosuav at gmail.com
Sat Sep 19 18:27:09 CEST 2015


On Sun, Sep 20, 2015 at 2:21 AM, Guido van Rossum <guido at python.org> wrote:
> Should it escape from plain parentheses? Which of these is better?
>
>   (a?.b) + c === (None if a is None else a.b) + c    # Fails unless c
> overloads None+c
>   (a?.b) + c === None if a is None else (a.b) + c    # Could be surprising
> if ? is deeply nested

My recommendation: It should _not_ escape. That way, you get control
over how far out the Noneness goes - you can bracket it in as tight as
you like.

ChrisA


More information about the Python-ideas mailing list