<div dir="ltr">Are you saying that hasattr returning False was hiding a bug or is a bug? The former could be annoying to track down, though hasattr(X, 'y') == True. For the latter, having hasattr return False if an AttributeError is raised would allow the property decorator to retain identical functionality if it is used to replace a (sometimes) existing attribute.</div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Dec 25, 2016 at 1:24 PM, Zahari Dim <span dir="ltr"><<a href="mailto:zaharid@gmail.com" target="_blank">zaharid@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
The other day I came across a particularly ugly bug. A simplified case<br>
goes like:<br>
<br>
class X:<br>
    @property<br>
    def y(self):<br>
        return self.nonexisting<br>
<br>
hasattr(X(),'y')<br>
<br>
This returns False because hasattr calls the property which in turn<br>
raises an AttributeError which is used to determine that the property<br>
doesn't exist, even if it does. This is arguably unexpected and<br>
surprising and can be very difficult to understand if it happens<br>
within a large codebase. Given the precedent with generator_stop,<br>
which solves a similar problem for StopIteration, I was wondering if<br>
it would be possible to have the __get__ method convert the<br>
AttributeErrors raised inside it to RuntimeErrors.<br>
<br>
The situation with this is a little more complicated because there<br>
could be a (possibly strange) where one might want to raise an<br>
AttributeError inside __get__. But maybe the specification can be<br>
changed so either `raise ForceAttributeError()` or `return<br>
NotImplemented` achieves the same effect.<br>
<br>
<br>
Merry Christmas!<br>
Zahari.<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
</blockquote></div><br></div>