astro py:docs

- Index
- Modules

### Navigation

- next »
- « previous |
- Astropy v5.2.1 »
- Astropy Core Package Utilities (`astropy.utils`) »
- isinstancemethod

# isinstancemethod

astropy.utils.introspection.isinstancemethod(cls, obj)

  Returns `True` if the given object is an instance method of the class it is defined on (as opposed to a `staticmethod` or a `classmethod`).

  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

      >>> class MetaClass(type):
      ...     def a_classmethod(cls): pass
      ...
      >>> class MyClass(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