Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def Class(*base_classes):
- def add_base_class_attrs_to_inst(instance):
- for cls in base_classes:
- for name, attr in cls().__dict__.items():
- if instance.__dict__.get(name) is None:
- instance.__dict__[name] = attr
- return instance
- def init_class(func):
- def wrapper(*args):
- instance = func(lambda: ..., *args)
- return add_base_class_attrs_to_inst(instance)
- return wrapper
- return init_class
- @Class()
- def BaseClass(self):
- def constructor():
- self.test = test
- self.test2 = test2
- return self
- def test():
- print('A test')
- def test2():
- print('A test2')
- return constructor()
- @Class()
- def BaseClass2(self):
- def constructor():
- self.test3 = test3
- return self
- def test3():
- print('A test3')
- return constructor()
- @Class(BaseClass, BaseClass2)
- def user(self, x):
- def constructor():
- self.x = x
- self.print_info = print_info
- self.test = test
- return self
- def print_info(self=self):
- print(f'x = {self.x}')
- def test():
- print('Is override')
- return constructor()
- c = user(1)
- c2 = user(122)
- c.print_info()
- c2.print_info()
- c2.test()
- c2.test2()
- c2.test3()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement