Given a class C
with a function or method f
, I use inspect.ismethod(obj.f)
(where obj
is an instance of C
) to find out if f
is bound method or not. Is there a way to do the same directly at the class level (without creating an object)?
inspect.ismethod does not work as this:
class C(object):
@staticmethod
def st(x):
pass
def me(self):
pass
obj = C()
results in this (in Python 3):
>>> inspect.ismethod(C.st)
False
>>> inspect.ismethod(C.me)
False
>>> inspect.ismethod(obj.st)
False
>>> inspect.ismethod(obj.me)
True
I guess I need to check if the function/method is member of a class and not static but I was not able to do it easily. I guess it could be done using classify_class_attrs
as shown here
How would you determine where each property and method of a Python class is defined?
but I was hoping there was another more direct way.