Is there any reason not to implement this using `@contextlib.contextmanager`?