Message 132471 - Python tracker (original) (raw)
Here I worked out a patch to make the function decorated by context manager returned by @contextmanager reusable, by storing original function object and argments(args, kwds objects) in _GeneratorContextManager and construct a generator when needed(in self.enter while used as a context manager and self.call while used as a decorator). It still inherit ContextDecorator to keep class inheritation complete and the call method is override.