python自定义classmethod


class B:

    def __get__(self, obj, cls):
        return 10

class M:

    def __init__(self, method):
        self.method = method


    def __get__(self, obj, cls):

        def inner(*args, **kwargs):
            print("M inner")
            return self.method(obj, *args, **kwargs)

        return inner


class Classmethod:

    def __init__(self, method):
        self.method = method


    def __get__(self, obj, cls):

        def inner(*args, **kwargs):
            return self.method(cls, *args, **kwargs)

        return inner





class A:

    b = B()


    # @classmethod
    @Classmethod
    def method(self):
        print("A method")
        return "a"

    # method = M(method)


if __name__ == "__main__":

    a = A()

    # print(a.method())

    print(a.method())
    print(A.method())

posted @ 2020-09-20 15:52  嗨,阿良  阅读(208)  评论(0编辑  收藏  举报