I was writing a metaclass to force docstring for class and instance method. Well to my surprise staticmethod and classmethod are not callable
just like instance method. I am not sure why?
class MyMeta(type):
def __new__(cls, name, parents, attrs):
print(cls, name, parents, attrs)
if "__doc__" not in attrs:
raise TypeError("Please define class level doc string!!!")
for key, value in attrs.items():
if callable(value) and value.__doc__ is None:
raise TypeError("Please define def level doc string!!!")
return super().__new__(cls, name, parents, attrs)
class A(metaclass=MyMeta):
"""This is API doc string"""
def hello(self):
""""""
pass
def __init__(self):
"""__init__ Method"""
pass
@classmethod
def abc(cls):
pass
I am not able to understand why are they not callable? They seems to pass my check if I don't define docstring for them.