I wonder why we need to use a try-finally when using a the @contextmanager decorator.
The provided example suggests:
from contextlib import contextmanager
@contextmanager
def managed_resource(*args, **kwds):
resource = acquire_resource(*args, **kwds)
try:
yield resource
finally:
release_resource(resource)
It seems to me, however, that this will do the exact same thing:
@contextmanager
def managed_resource(*args, **kwds):
resource = acquire_resource(*args, **kwds)
yield resource
release_resource(resource)
I'm sure I must be missing something. What am I missing?