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

Jonathan Fine jfine2358 at gmail.com
Wed Aug 1 10:04:40 EDT 2018


Hi Steve

Thank you for your reply.

We're discussing the abstract to PEP 505, which writes
 ===
The "None-aware attribute access" operator ?. ("maybe dot") evaluates
the complete expression if the left hand side evaluates to a value
that is not None
===

I gave (42).str as an example. I wrote

> I don't see how to apply the prose in the abstract to this last
> example. The left hand side is not None, so we "evaluate the complete
> expression". On one reading, this is a recursion.

You wrote
> The phrasing could be clearer.

I think the phrasing could be considerably improved (see below).

> Since 42 is not None, it evaluates (42).str
> [...]

Based on this hint, here's what I think is a better statement.
===
Let `lhs` be the value of the left hand side, and RHS the code
fragment on the right hand side. If `lhs` is None, then the whole
expression is `None`. Otherwise, `lhs . RHS` gives the value of the
whole expression.
===

Please would the experts tell me: Is it true? And if true, is it
better? And can it be improved?

-- 
Jonathan


More information about the Python-ideas mailing list