What about re-using try? Crystal does this (http://play.crystal-lang.org/#/r/gf5):

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@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@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/



--
Ryan
[ERROR]: Your autotools build scripts are 200 lines longer than your program. Something’s wrong.