How can I tell if a given method is a classmethod or instancemethod in Python?
Checking to see if m.im_self is the class works some of the time but doesn't seem开发者_Go百科 to be 100% reliable (ex. if you use multiple decorators on a method.)
If it's a bound method on the class then it's a classmethod.
from inspect import ismethod, isclass
def isclassmethod( m ):
return ismethod(m) and isclass(m.__self__)
精彩评论