<p dir="ltr">Ok, I have been thinking of the behavior too broadly. I realize now that `x?.foo` might still simply raise an AttributeError if x is neither None nor a thing with a foo attribute.</p>
<p dir="ltr">The class I wrote is definitely too aggressive for the behavior described. On the other hand, by being narrower in behavior there feels like even less motivation for new syntax.</p>
<div class="gmail_extra"><br><div class="gmail_quote">On Sep 10, 2016 6:29 PM, "MRAB" <<a href="mailto:python@mrabarnett.plus.com">python@mrabarnett.plus.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 2016-09-11 02:02, David Mertz wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Sat, Sep 10, 2016 at 5:23 PM, Guido van Rossum <<a href="mailto:guido@python.org" target="_blank">guido@python.org</a><br>
<mailto:<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>>> wrote:<br>
<br>
    No. PEP 505 actually solves the problem without ever catching<br>
    AttributeError. Please read it.<br>
<br>
<br>
I read it again (I did a year ago, but reviewed it now).  I hadn't been<br>
thinking that the *mechanism* of a new None-coalescing operator would<br>
actually be catching an exception.  It could (and should) work<br>
differently if it becomes syntax.<br>
<br>
What I was getting at with "essentially" was that it would *do the same<br>
thing* that an AttributeError does.  That is, if `x.foo` can't be<br>
evaluated (i.e. x doesn't have an attribute 'foo'), then access is<br>
informally "an error."  The hypothetical "x?.foo" catches that "error"<br>
and substitutes a different value.  The particular implementation<br>
under-the-hood is less important for most programmers who might use the<br>
construct (and I think documentation would actually give an informal<br>
equivalent as something similar to what I put in the NoneCoalesce class).<br>
<br>
</blockquote>
x?.foo would lookup attribute 'foo' _unless_ x was None, in which case it would return None. It's simply:<br>
<br>
    None if x is None else x.foo<br>
<br>
This means that None?.__str__() would return None, not 'None'. (None has an attribute called '__str__', and None.__str__() returns 'None', but it would not be looked up because None is, well, None.)<br>
<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofco<wbr>nduct/</a><br>
</blockquote></div></div>