Revisiting PEP 505 – None-aware operators

Because the semantics in case (1) are different, while for case (2) and (3) there is no semantic difference.

I think we can generate some kind of wrapper node for a parenthesized ‘?.’ operator. It may not be pretty given that the AST for expressions without ’?’ must not change, but it can and should be done.

Type checkers should be able to infer that ‘(a.b?.c.d).repr()’ has type ‘str’ while ‘a.b?.c.d.repr()’ is ‘str|None’.

3 Likes