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

Ron Adam ron3200 at gmail.com
Sat Oct 3 22:27:20 CEST 2015


On 10/02/2015 02:56 PM, Andrew Barnert via Python-ideas wrote:
>> It's not quite the same.  The proposed ?( skips the arguments if
>> the right hand side is None.
>>>
>>> None?(...)   ---> None
>>>
>>> So you can't use that to supply a default directly.
>>>
>>> value = None?(default)    # returns None (not useful here)
> Again, why would you want that to return default?

I guess it depends on what you think it should do.  None is a type, 
NoneType to be exact, then if like int, or float, what kind of argument 
should it have?

'' and empty containers come to mind.  Just like float and int can take 
'1', and error if you give it something that can't be converted to a 
float or int.

The None?(...) syntax looks like it should do a call.  Just like it 
would do if you did int?(...).

So both the return None and the return everything are special behaviors. 
  Possibly a None result is a bit more correct.

To tell the truth I think looking at some real examples from the library 
would be good.  How can those be improved both in how they read and how 
they look, and how frequent are they?

This whole line of discussion started out as a very tenuous 
suggestion/possibility.  I even said it was going out on a limb, so I 
really wasn't expecting to defend it as if it was a complete idea.

The concept I am thing of is doable, but not in the way I was thinking 
at first, but I also think it doesn't fit with python very well.

Cheers,
    Ron








More information about the Python-ideas mailing list