[Python-ideas] Null coalescing operator
Greg Ewing
greg.ewing at canterbury.ac.nz
Wed Nov 2 18:22:45 EDT 2016
Zero Piraeus writes:
>
> If I write something like obj.attr, the failure mode I care about is
> that
> obj has no attribute attr, rather than that obj is specifically None (or
> one of a defined group of somewhat Nonelike objects).
>
> Clearly, in such a circumstance, obj is not what I expected it to be,
> because I thought it was going to have an attribute attr, and it
> doesn't.
If it's an error, you shouldn't be trying to do anything
about it, just let the exception happen.
The proposed .? syntax is designed for cases where it's *not*
an error for the object to be missing the attribute, *and*
the correct action in that situation is to skip whatever
you would have done otherwise.
What needs to be decided is whether such use cases are frequent
enough to justify special syntax.
--
Greg
More information about the Python-ideas
mailing list