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

Jonathan Fine jfine2358 at gmail.com
Tue Jul 31 15:53:50 EDT 2018


Stephan Houben wrote:

> Nope, the introduction of the tmp variable changed the semantics. It isn't a
> "chain" anymore so it breaks shortcutting.

I'm confused. Assume 'a' is not defined.

With Python's dot (attribute access) we have
>>> a.b.c
NameError: name 'a' is not defined
>>> a.(b.c)
SyntaxError: invalid syntax
>>> (a.b).c
NameError: name 'a' is not defined

I'd expect, after PEP 505 is added to Python that we'd get
>>> a ?. b ?. c
NameError: name 'a' is not defined
>>> a ?. (b ?. c)
SyntaxError: invalid syntax
>>> (a ? . b) ?. c
NameError: name 'a' is not defined

If this is not correct, please some do tell me what we would get.

Now assume 'a' is defined. I'd also expect, for any value for 'a', that
>>> tmp = (a ?. b)
>>> val = tmp ?. c
give val the same value as
>>> val = (a ?. b) ?. c

If this is not so, then can the second val be computed from tmp? And if so, how?

-- 
Jonathan


More information about the Python-ideas mailing list