class Open: def __enter__(self): print('in'); return self def __exit__(self, *a): print('out') with Open(): print('mid')