[Python-ideas] Add a "hasmethod()" builtin?
Gregory P. Smith
greg at krypto.org
Sat Sep 1 02:03:54 CEST 2012
On Wed, Aug 29, 2012 at 9:28 PM, Steven D'Aprano <steve at pearwood.info>wrote:
> On Wed, Aug 29, 2012 at 03:48:01PM -0700, Guido van Rossum wrote:
> > There's a concept that's sometimes useful when explaining behavior of
> > certain Python operations in terms of simpler ones, and it is "does
> > the class of x define a method m?".
> It's not just methods where this is useful. For example, the help()
> quasi-builtin ignores instance attribute x.__doc__ and instead uses
> I'm not sure that needing this is common enough to justify builtins, but
> I think it would be useful to have hastypeattr and friends (get*, set*
> and del*) in the operator module.
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 (*).
(*) 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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas