Nick Coghlan <ncogh...@gmail.com> added the comment: On Wed, Mar 23, 2011 at 12:04 PM, Antoine Pitrou <rep...@bugs.python.org> wrote: > Clearly there is a problem in the API or its implementation, as in a function > decorated with a context manager can only be invoked once! This isn't good...
The problem stems from a fundamentally bad call on my part: making ContextGenerator inherit from ContextDecorator. I failed to account for the fact that in order to work correctly the latter requires "reusable" context managers that can be used more than once, but ContextGenerator objects are one-shots (i.e. once __enter__ has been called once, you can't use them again). We can either hack this to work by providing ContextDecorator with a way to get the underlying context manager to create a new copy of itself each time, or else revert to the 3.1 status quo and declare that context managers created via contextlib.contextmanager simply can't be used as decorators. I'm inclined to favour the latter option. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue11647> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com