[Python-ideas] PEP 505: None-aware operators
INADA Naoki
songofacandy at gmail.com
Thu Jul 19 04:25:53 EDT 2018
Honestly speaking, I don't want make Python syntax more complex.
But when comparing to accepted PEP 572, I think this PEP is useful
often enough. And PEP 505 doesn't break border between
expression and statement unlike PEP 572.
Especially, ?? and ??= seems useful very often.
And `x ?? default` seems much more readable than
`x if x is not None else default` or `default if x is None else x`.
On the other hand, `?.` and `?[]` seems useful less often and more confusing.
When looking `spam?.egg`, people can expect `getattr(spam, 'egg', None)`
rather than `spam.egg if spam is not None else None`.
Since `?.` and `?[]` can't avoid AttributeError, IndexError and KeyError,
I think it's confusing and not useful enough compared with it's ugliness.
So my current position is +1 for `??` and `??=`, but -1 for others.
Regards,
--
INADA Naoki <songofacandy at gmail.com>
More information about the Python-ideas
mailing list