Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyBoundClassMethod:
- def __init__(self, func, cls):
- self.func = func
- self.cls = cls
- def __call__(self, *args, **kwargs):
- return self.func(self.cls, *args, **kwargs)
- class MyClassMethod:
- def __init__(self, func):
- self.func = func
- def __get__(self, instance, owner):
- return MyBoundClassMethod(self.func, owner)
- class MyClass:
- @classmethod
- def print_message(cls, msg):
- print(f"id {id(cls)}, self {cls}, '{msg}'")
- @MyClassMethod
- def print_message_2(cls, msg):
- print(f"id {id(cls)}, self {cls}, '{msg}'")
- MyClass.print_message("Hi there")
- MyClass.print_message_2("Hi there")
- my_obj = MyClass()
- my_obj.print_message("Hi there")
- my_obj.print_message_2("Hi there")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement