all Python 3inspectfunction
inspect.ismethoddescriptor()
descriptors
Checks that an object is a method descriptor: it has __get__ but neither __set__ nor __delete__ (for example int.__add__, list.append).
Syntax
inspect.ismethoddescriptor(object) -> bool
Functions and classes are excluded even though a function has __get__: ismethoddescriptor returns False for them because isfunction and isclass 'promise more'. The classmethod and staticmethod objects taken from a class __dict__, however, are method descriptors. The typical place you meet one is list.append: it is neither a builtin nor a function but exactly a method descriptor.
Examples
import inspect
class A:
def m(self): pass
@classmethod
def cm(cls): pass
print(inspect.ismethoddescriptor(list.append)) # → True
print(inspect.ismethoddescriptor(A.__dict__['m'])) # → False — это функция
print(inspect.ismethoddescriptor(A.__dict__['cm'])) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy