isinstancemethod¶
-
astropy.utils.introspection.
isinstancemethod
(cls, obj)[source] [edit on github]¶ Returns
True
if the given object is an instance method of the class it is defined on (as opposed to astaticmethod
or aclassmethod
).This requires both the class the object is a member of as well as the object itself in order to make this determination.
Parameters: cls :
type
The class on which this method was defined.
obj :
object
A member of the provided class (the membership is not checked directly, but this function will always return
False
if the given object is not a member of the given class).Examples
>>> from astropy.extern import six >>> class MetaClass(type): ... def a_classmethod(cls): pass ... >>> @six.add_metaclass(MetaClass) ... class MyClass(object): ... __metaclass__ = MetaClass ... def an_instancemethod(self): pass ... @classmethod ... def another_classmethod(cls): pass ... @staticmethod ... def a_staticmethod(): pass ... >>> isinstancemethod(MyClass, MyClass.a_classmethod) False >>> isinstancemethod(MyClass, MyClass.another_classmethod) False >>> isinstancemethod(MyClass, MyClass.a_staticmethod) False >>> isinstancemethod(MyClass, MyClass.an_instancemethod) True