<br><br><div class="gmail_quote">On Thu, Jul 11, 2013 at 10:50 AM, Mark McLoughlin <span dir="ltr"><<a href="mailto:markmc@redhat.com" target="_blank">markmc@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Wed, 2013-07-10 at 21:14 +0200, Thomas Hervé wrote:<br>
><br>
><br>
> On Wed, Jul 10, 2013 at 8:32 PM, Mark McLoughlin <<a href="mailto:markmc@redhat.com">markmc@redhat.com</a>><br>
> wrote:<br>
>         On Wed, 2013-07-10 at 11:01 -0700, Nachi Ueno wrote:<br>
><br>
>         > Personally, I prefer not to use exception for such cases.<br>
><br>
><br>
><br>
> The key here is "personally". I don't think we have to agree on all<br>
> style issues.<br>
<br>
</div>When it results in a patch submitter getting a -1 from one person for<br>
choosing EAFP and a -1 from another person for choosing LBYL, then<br>
yes ... actually we do need to agree.<br>
<div class="im"><br></div></blockquote><div><br></div><div>I feel there is no perfect answer here, it depends on the particular piece of code. Reviews should mostly focus on the overall model and logic, not whether 2 lines should be written one way or another. This is blatant bikeshedding.</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><br>
> hasattr is a bit dangerous as it catches more exceptions than it needs<br>
> too. See for example<br>
> <a href="http://stackoverflow.com/questions/903130/hasattr-vs-try-except-block-to-deal-with-non-existent-attributes/16186050#16186050" target="_blank">http://stackoverflow.com/questions/903130/hasattr-vs-try-except-block-to-deal-with-non-existent-attributes/16186050#16186050</a> for an explanation.<br>

<br>
</div>That answer does begin with this, though:<br>
<br>
  I almost always use hasattr: it's the correct choice for most cases.<br>
<br>
and, frankly, a __getattr__() method that returns ValueError is broken.<br>
<br>
i.e. the conclusion would be that we should only avoid hasattr() in some<br>
very limited cases where the underlying __getattr__() does weird things<br>
or where using it can result in a race condition.<br></blockquote><div><br></div><div>Personally I'd rather use something that works 100% of the time than something that only works 99.9% of the time. I agree that a __getattr__ raising ValueErro is broken, but if you're already using hasattr you'll only know until it's too late.</div>
<div><br></div><div>Also never have attributes conditionally it's terrible :).</div><div><br></div><div>Regards,</div><div><br></div><div>-- </div><div>Thomas</div><div> </div></div>