How to decide if a object is instancemethod?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Mar 14 19:30:27 EDT 2012


On Thu, 15 Mar 2012 08:26:22 +1100, Ben Finney wrote:

> Jon Clements <joncle at googlemail.com> writes:
> 
>> import inspect
>> if inspect.ismethod(foo):
>>    # ...
>>
>> Will return True if foo is a bound method.
> 
> But under what other conditions will it return True? The name suggests
> that *any* method – static method, class method, bound method, unbound
> method – will also result in True.
> 
> The documentation says only “instance method”, though. Confusing :-(


Bound and unbound methods are instance methods. To be precise, the 
"method" in "(un)bound method" stands for instance method, and the 
difference between the two in Python 2.x is a flag on the method object. 
(Unbound methods are gone in Python 3.)

Class and static methods are not instance methods. I suppose it is 
conceivable that you could have an unbound class method in theory, but I 
can't see any way to actually get one in practice.

In Python, and probably most languages, a bare, unadorned "method" is 
implied to be an instance method; "instance method" is (possibly) a 
retronym to distinguish them from other, newer(?), types of method.

http://en.wikipedia.org/wiki/Retronym



-- 
Steven



More information about the Python-list mailing list