I executed the following Python code:
class C:
def m1(self):
print('method m1')
def m2(self):
print('method m2')
@classmethod
def m3(cls):
print('class method')
@staticmethod
def m4():
print('static method')
print()
for key, val in vars(C).items():
print(key, '***', val, end=' ')
if callable(val):
print(True)
else:
print(False)
Got the following output:
__module__ *** __main__ False
m1 *** <function C.m1 at 0x7f3661a62dc0> True
m2 *** <function C.m2 at 0x7f3661a735e0> True
m3 *** <classmethod object at 0x7f3661bd4670> False
m4 *** <staticmethod object at 0x7f3661ab4f10> False
__dict__ *** <attribute '__dict__' of 'C' objects> False
__weakref__ *** <attribute '__weakref__' of 'C' objects> False
__doc__ *** None False
I am wondering why callable
returns False
for @classmethod
and @staticmethod
.
I am actually trying to find out the names of all methods inside a class so that I can decorate all methods of the class with a user defined decorator