fork download
  1. import contextlib
  2.  
  3. class Open:
  4. def __enter__(self):
  5. return None
  6. def __exit__(self, exc_type, exc_val, exc_tb):
  7. pass
  8.  
  9.  
  10. class Pituh:
  11. def kok(self):
  12. print("kok")
  13.  
  14. @contextlib.contextmanager
  15. def get_complex_pituh():
  16. with Open():
  17. yield Pituh()
  18.  
  19.  
  20. @contextlib.contextmanager
  21. def get_pituhs():
  22. with contextlib.ExitStack() as s:
  23. yield [s.enter_context(get_complex_pituh())]
  24.  
  25.  
  26. with get_pituhs() as pituhs:
  27. kok = pituhs[0]
  28. print(type(kok))
  29. kok.kok()
Success #stdin #stdout 0.02s 9168KB
stdin
Standard input is empty
stdout
<class '__main__.Pituh'>
kok