[Python-ideas] Null coalescing operators

Ryan Gonzalez rymg19 at gmail.com
Mon Sep 21 19:10:04 CEST 2015

What about re-using try? Crystal does this (

v = "ABC"
puts nil == v.try &.downcase # prints true
v = nil
puts nil == v.try &.downcase # prints false

Python could use something like:

v = 'ABC'
print(v try.downcase is None) # prints False
v = None
print(v try.downcase is None) # prints True

(Of course, the syntax would be a little less...weird!)

On Mon, Sep 21, 2015 at 10:40 AM, Guido van Rossum <guido at python.org> wrote:

> Just to cut this thread short, I'm going to reject PEP 505, because ? is
> just too ugly to add to Python IMO. Sorry.
> I commend Mark for his clean write-up, without being distracted, giving
> some good use cases. I also like that he focused on a minimal addition to
> the language and didn't get distracted by hyper-generalizations.
> I also like that he left out f?(...) -- the use case is much weaker;
> usually it's the object whose method you're calling that might be None, as
> in title?.upper().
> Some nits for the PEP:
> - I don't think it ever gives the priority for the ?? operator. What would
> "a ?? b or c" mean?
> - You don't explain why it's x ?? y but x ?= y. I would have expected
> either x ? y or x ??= y.
> - You don't explain or show how far ?. reaches; I assume x?y.z is
> equivalent to None if x is None else x.y.z, so you don't have to write
> x?.y?.z just to handle x.y.z if x is None.
> - The specification section is empty.
> --
> --Guido van Rossum (python.org/~guido)
> _______________________________________________
> 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/

[ERROR]: Your autotools build scripts are 200 lines longer than your
program. Something’s wrong.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150921/62f9a350/attachment.html>

More information about the Python-ideas mailing list