Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. def cast(cls, self):
  2. class _:
  3. def __getattribute__(_, name):
  4. attr = getattr(cls, name)
  5. if callable(attr):
  6. def _(*args, **kargs):
  7. return attr(self, *args, **kargs)
  8. return _
  9. else:
  10. return getattr(self, name)
  11. return _()
  12.  
  13. class A:
  14. def func(self):
  15. print('A')
  16.  
  17. class B(A):
  18. def func(self):
  19. print('B')
  20.  
  21. b = B()
  22. b.func() # => B
  23. cast(A, b.func() # => A
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement