How to check if a function is a method of some object?
For example:
def check_method(f):
...
check_method(lambda x: x + 1) # >>>
Use inspect.ismethod().
The documentation states:
Return true if the object is a bound method written in Python.
This means that it will work as you intend for classes that you define in Python. However, for methods of built-in classes like list
or classes implemented in extension modules it will return False
.