[issue11647] function decorated with a context manager can only be invoked once

ysj.ray report at bugs.python.org
Tue Mar 29 16:23:59 CEST 2011


ysj.ray <ysj.ray at gmail.com> added the comment:

> For 3.3, the fix could be generalised with ContextDecorator supporting a documented "self._recreate" internal interface that, by default, just returns self, but would be overridden in _GeneratorContextManager to actually create a new instance. The custom __call__ implementation for _GeneratorContextManager could then be removed.

How about directly using the existing "copy.copy()" semantics instead of self._recreate()? That is, call "with copy.copy(self)" instead of "with self" in ContextGenerator.__call__(), implement ContextGenerator.__copy__() method to simply return self, and implement  _GeneratorContextManager.__copy__() to create a copy of itself. This saves an internal interface.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11647>
_______________________________________


More information about the Python-bugs-list mailing list