fork(1) download
  1. class Base:
  2. def open(self): pass
  3. def read(self): pass
  4.  
  5. class A(Base):
  6. def read(self): pass
  7.  
  8. class B(Base):
  9. def read(self): pass
  10.  
  11. class Mixin:
  12. def feature(self): pass
  13.  
  14. def add_mixin(item, mixin):
  15. class _Proxy(Base):
  16. def __getattribute__(self, name):
  17. try:
  18. return getattr(item, name)
  19. except AttributeError:
  20. return getattr(mixin, name).__get__(item)
  21. return _Proxy()
  22.  
  23. for Item in (A, B):
  24. item = Item()
  25. item = add_mixin(item, Mixin)
  26. assert isinstance(item, Base)
  27. assert item.open.__func__ is Base.open
  28. assert item.read.__func__ is Item.read
  29. assert item.feature.__func__ is Mixin.feature
Success #stdin #stdout 0.03s 9500KB
stdin
Standard input is empty
stdout
Standard output is empty