[Python-ideas] Null coalescing operators

Guido van Rossum guido at python.org
Tue Sep 22 01:51:50 CEST 2015


On Mon, Sep 21, 2015 at 4:47 PM, Random832 <random832 at fastmail.com> wrote:

> On Mon, Sep 21, 2015, at 17:48, Guido van Rossum wrote:
> > This is important when x is a more complex expression that is either
> > expensive or has a side-effect. E.g. d.get(key)?.upper() would currently
> > have to be spelled as (some variant of) "None if d.get(key) is None else
> > d.get(key).upper()" and the ?? operator doesn't really help for the
> > repetition -- it would still be "d.get(key) ?? d.get(key).upper()".
>
> ?? is meant to use the right if the left *is* null, as I understand it.
> So this isn't a problem it solves at all.
>

Sorry, my bad. Indeed, x ?? y tries to fix the issue that "x or y" uses y
if x is falsey. Still this seems a lesser problem to me than the problem
solved by x?.a and x?[y]. Most of the time in my code it is actually fine
to use the default if the LHS is an empty string.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150921/6ba2f018/attachment.html>


More information about the Python-ideas mailing list