from contextlib import contextmanager class A(): def b(self): return "Hello" @property def cm(self): @contextmanager def stuff(): print("start") try: yield None #yield 2 except Exception: pass print("end") return stuff def p(self): with self.cm() as i: print(f"{i} middle") raise Exception a=A() a.p()