from contextlib import contextmanager
@contextmanager
def managed():
print("enter")
try:
yield "resource"
except ValueError:
print("handled")
finally:
print("exit")
with managed() as r:
print(r)
raise ValueError("oops")
print("done")
