<br><br><div class="gmail_quote">On Wed, Nov 30, 2011 at 11:51, Mark Voorhies <span dir="ltr"><<a href="mailto:mark.voorhies@ucsf.edu">mark.voorhies@ucsf.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
On Wednesday, November 30, 2011 10:00:54 am Thomas Kluyver wrote:<br>
<snip><br>
<div class="im">> I maintain that altering state on attribute access, while it's perfectly<br>
> possible, is almost always a bad idea, for pretty much this reason: you can<br>
> do very useful things by assuming that you're free to inspect attributes.<br>
<br>
</div>I tend to agree with you. On the other hand, it's legal in the language, and<br>
there is no C++-like concept of a const method to block this sort of side effect<br>
(meaning that people will do this sort of thing both deliberately and inadvertently).<br>
<br></blockquote><div><br></div><div><div>Python is a language of unenforced convention, which allows for this kind of magic vs magic conflict.</div><div><br></div><div>IPython's expectation that hasattr is safe is a reasonable one, as is Traits' expectation that getattr</div>
<div>will only be called when the attribute is actually requested.</div><div><br></div><div>But Traits' behavior invalidates hasattr, and IPython's behavior can trigger unrequested events.</div><div><br></div><div>
It would be nice if there was a corresponding `__hasattr__`, so that checking for attribute existence</div></div><div>could bypass side effects in objects that do getattr magic that should only be triggered on *real* getattr.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Given that lack of autocall fails loudly and multiple attribute access fails silently,<br>
I think that setting the default to "fail loudly" (no autocall) makes sense.<br></blockquote><div><br></div><div>This makes perfect sense, and is a good general rule for such decisions.</div><div>I do think it will be newcomers using IPython to learn Python who will be</div>
<div>most adversely affected by the change, because a SyntaxError</div><div>is not helpful, while correcting the user is instructive.</div><div><br></div><div>-MinRK</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<font color="#888888"><br>
--Mark<br>
</font><div><div></div><div class="h5"><br>
_______________________________________________<br>
IPython-dev mailing list<br>
<a href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/ipython-dev" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
</div></div></blockquote></div><br>