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())
抟扶摇而上者九万里