Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def cast(cls, self):
- class _:
- def __getattribute__(_, name):
- attr = getattr(cls, name)
- if callable(attr):
- def _(*args, **kargs):
- return attr(self, *args, **kargs)
- return _
- else:
- return getattr(self, name)
- return _()
- class A:
- def func(self):
- print('A')
- class B(A):
- def func(self):
- print('B')
- b = B()
- b.func() # => B
- cast(A, b.func() # => A
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement