classmethod
and staticmethod
return descriptor objects, not functions. Most decorators are not designed to accept descriptors.
Normally, then, you must apply classmethod
and staticmethod
last when using multiple decorators. And since decorators are applied in "bottom up" order, classmethod
and staticmethod
normally should be top-most in your source.
Like this:
class My_class(object):
@classmethod
@print_function_name
def get_dir(cls):
return dir(cls)
@staticmethod
@print_function_name
def get_a():
return 'a'
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…