[Python-ideas] Fwd: Null coalescing operator
David Mertz
mertz at gnosis.cx
Sat Sep 10 21:02:51 EDT 2016
On Sat, Sep 10, 2016 at 5:23 PM, Guido van Rossum <guido at python.org> wrote:
> No. PEP 505 actually solves the problem without ever catching
> AttributeError. Please read it.
>
I read it again (I did a year ago, but reviewed it now). I hadn't been
thinking that the *mechanism* of a new None-coalescing operator would
actually be catching an exception. It could (and should) work differently
if it becomes syntax.
What I was getting at with "essentially" was that it would *do the same
thing* that an AttributeError does. That is, if `x.foo` can't be evaluated
(i.e. x doesn't have an attribute 'foo'), then access is informally "an
error." The hypothetical "x?.foo" catches that "error" and substitutes a
different value. The particular implementation under-the-hood is less
important for most programmers who might use the construct (and I think
documentation would actually give an informal equivalent as something
similar to what I put in the NoneCoalesce class).
--
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons. Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160910/cd550dbd/attachment.html>
More information about the Python-ideas
mailing list