Python 3.11+inspectfunction
inspect.ismethodwrapper()
descriptors
Checks that an object is a method-wrapper: a special method of a built-in type already bound to an instance, like (1).__add__.
Syntax
inspect.ismethodwrapper(object) -> bool
Tell the pair apart: int.__add__ is a descriptor (wrapper_descriptor), while (1).__add__ is a method-wrapper bound to the number. ismethod is False for it and so is isbuiltin, so code hunting for 'methods' via ismethod misses these objects. They show up on your own objects too: obj.__str__ inherited from object is also a method-wrapper.
Examples
import inspect
class A: pass
print(inspect.ismethodwrapper((1).__add__)) # → True
print(inspect.ismethodwrapper(int.__add__)) # → False — это дескриптор
print(inspect.ismethodwrapper(A().__str__), inspect.ismethod(A().__str__)) # → True False
See also
Open in the full glossarydocs.python.orgReport an inaccuracy