This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients michael.foord, ncoghlan, pitrou
Date 2011-03-23.04:10:40
SpamBayes Score 1.5415959e-06
Marked as misclassified No
Message-id <>
In-reply-to <>
On Wed, Mar 23, 2011 at 12:04 PM, Antoine Pitrou <> 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.
Date User Action Args
2011-03-23 04:10:41ncoghlansetrecipients: + ncoghlan, pitrou, michael.foord
2011-03-23 04:10:41ncoghlanlinkissue11647 messages
2011-03-23 04:10:41ncoghlancreate