<br><div class="gmail_quote">On Wed, Aug 29, 2012 at 9:28 PM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</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, Aug 29, 2012 at 03:48:01PM -0700, Guido van Rossum wrote:<br>
</div><div class="im">> There's a concept that's sometimes useful when explaining behavior of<br>
> certain Python operations in terms of simpler ones, and it is "does<br>
> the class of x define a method m?".<br>
<br>
</div>It's not just methods where this is useful. For example, the help()<br>
quasi-builtin ignores instance attribute x.__doc__ and instead uses<br>
type(x).__doc__.<br>
<br>
I'm not sure that needing this is common enough to justify builtins, but<br>
I think it would be useful to have hastypeattr and friends (get*, set*<br>
and del*) in the operator module.<br></blockquote><div><br></div><div>+1.</div><div><br></div><div>I wouldn't call it hasmethod as described either as that name implies to most readers the much simpler "it has a callable attribute with this name" check rather than getting into the differences between an arbitrary callable attribute, function, or an actual method on the type which most people do not need to know about (*).</div>

<div><br></div><div>-gps</div><div><br></div><div>(*) unless mocking, i ran into a test failure because for 2.6 it was stubbing out a __special__ method with a mock no longer worked in 2.7. but that test was better all around when refactored to not need to be that crazy. :)</div>

</div>