实现 classmethod装饰器

【实现 classmethod装饰器】实现 classmethod装饰器

from functools import wraps, partial class Classmethod: def __init__(self, method): wraps(method)(self) def __get__(self, instance, cls): return partial(self.__wrapped__, cls) class C: @Classmethod def method(cls): print(cls) @Classmethod def method2(cls, x): print(cls) print(x) c =C() c.method() c.method2(1)

    推荐阅读