[Python-ideas] PEP 505: None-aware operators

Rhodri James rhodri at kynesim.co.uk
Tue Jul 31 14:35:43 EDT 2018


On 31/07/18 18:46, Steven D'Aprano wrote:
> n Mon, Jul 30, 2018 at 12:41:20PM -0500, Abe Dillon wrote:
> 
> [Rhodri James]
>>> On 29/07/18 16:12, Abe Dillon wrote:
>>>   > spam?.eggs.cheese.aardvark  # why would you ever do this?
>>>
>>> If you knew that if you really have something in "spam", your program
>>> guarantees it will have an "eggs" attribute with a "cheese" attribute, etc,
>>> you just don't know if "spam" is not None.  It's the same insider knowledge
>>> you would use if you wrote it out as
>>>
>>> spam.eggs.cheese.aardvark if spam is not None else None
>>
>> That's not the equivalent as described in PEP 505.
> Yes it is. Rhodri is correct, although I admit that I hadn't realised
> this point myself until he pointed it out. (That is why until now I've
> been writing examples like "spam?.eggs?.cheese?.aardvark" which is
> redundant.)

Doh!  Yes, of course, the point was it was short-circuiting.  This keeps 
confusing me (easily done, I'll admit), which is probably not a point in 
its favour.

-- 
Rhodri James *-* Kynesim Ltd


More information about the Python-ideas mailing list