fork download
  1. from inspect import ismethod
  2.  
  3. class A:
  4. @property
  5. def prop(self) -> int:
  6. return 1
  7.  
  8. def method(self) -> int:
  9. return self.prop * 2
  10.  
  11. class B:
  12. def __init__(self, a: A):
  13. self._a = a
  14.  
  15. @property
  16. def prop(self) -> int:
  17. return 2
  18.  
  19. def __getattr__(self, attr):
  20. value = getattr(self._a, attr)
  21. if ismethod(value):
  22. value = value.__func__.__get__(self)
  23. return value
  24.  
  25. b = B(A())
  26. print(b.prop)
  27. print(b.method())
Success #stdin #stdout 0.23s 18540KB
stdin
Standard input is empty
stdout
2
4