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

2012-05-19 Thread Eric Snow
Changes by Eric Snow : -- nosy: +eric.snow ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.o

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

2012-05-19 Thread Nick Coghlan
Nick Coghlan added the comment: I'm closing this *without* converting ContextDecorator._recreate_cm() to a public method (although I'm also attaching the patch that would have done exactly that). My rationale for doing so is that I *still* consider making _GeneratorContextManager a subclass

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

2011-12-17 Thread Nick Coghlan
Nick Coghlan added the comment: I'm prototyping a public version of the recreation API as "ContextDecorator.refresh_cm()" in contextlib2: http://contextlib2.readthedocs.org/en/latest/index.html#contextlib2.ContextDecorator.refresh_cm -- type: behavior -> enhancement _

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

2011-12-12 Thread Giampaolo Rodola'
Changes by Giampaolo Rodola' : -- nosy: +giampaolo.rodola ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http:

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

2011-05-05 Thread Nick Coghlan
Nick Coghlan added the comment: The core bug has been fixed for 3.2.1 and forward ported to 3.3. I credited the patch to "Ysj Ray" in ACKS and NEWS, let me know if you'd prefer a different attribution. Leaving the issue open for now, since _recreate_cm() should be renamed and documented for

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

2011-05-05 Thread Roundup Robot
Roundup Robot added the comment: New changeset e4ba097123f6 by Nick Coghlan in branch '3.2': Issue #11647: allow contextmanager objects to be used as decorators as described in the docs. Initial patch by Ysj Ray. http://hg.python.org/cpython/rev/e4ba097123f6 New changeset b23d1df7e47e by Nick

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

2011-05-05 Thread Nick Coghlan
Changes by Nick Coghlan : -- assignee: -> ncoghlan versions: +Python 3.2, Python 3.3 ___ Python tracker ___ ___ Python-bugs-list mail

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

2011-03-30 Thread ysj.ray
ysj.ray added the comment: Got it. Here is my updated patch. Not sure if the doc is proper. -- Added file: http://bugs.python.org/file21475/issue_11647_2.diff ___ Python tracker ___

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

2011-03-29 Thread Michael Foord
Michael Foord added the comment: I agree. copy is a separate protocol and shouldn't be involved here. -- ___ Python tracker ___ ___ P

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

2011-03-29 Thread Nick Coghlan
Nick Coghlan added the comment: Because I don't want to conflate the two APIs. ContextDecorator can be used with *any* context manager, and some of those may already be using their copy semantics for something else. If anyone ever writes the __with__ PEP, then ContextDecorator._recreate can b

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

2011-03-29 Thread ysj.ray
ysj.ray 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 __c

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

2011-03-29 Thread Nick Coghlan
Nick Coghlan added the comment: Part of the problem is that there was a specific reason we didn't go with lazy initialisation of the internal generator: lazy initialisation means there can be an arbitrary delay between creation of the context manager and the creation of the underlying generat

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

2011-03-29 Thread ysj.ray
ysj.ray added the comment: 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__

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

2011-03-28 Thread ysj.ray
ysj.ray added the comment: Now I found that I am wrong and I feel OK with make the context manager reusable when used as a decorator. I missed one thing: the reusable behavior is regarded as in the decorated function but not in the decorator context manager. :) -- _

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

2011-03-25 Thread Michael Foord
Michael Foord added the comment: I'm strongly with Antoine on this. If you use context manager as a decorator you should be able to reuse it - and in general both generators and context managers can be reused and so I don't understand the phrase 'moral equivalent of the implicit context manag

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

2011-03-25 Thread Antoine Pitrou
Antoine Pitrou added the comment: > Because there is no *OBVIOUS* code or sign which can illustrate that > context manager changes from a one-shot to a reusable. I'm talking about the decorator, not the context manager. Surely there is a way for the decorator to instantiate a new context manage

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

2011-03-25 Thread Ray.Allen
Ray.Allen added the comment: > > Agreed with nick's idea, the implicitly recreation of the context > > managers would confuse users. > Uh, why would it? That's exactly what I expect the decorator to do, and > I was astonished to discover that it *doesn't*. Because there is no *OBVIOUS* code o

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

2011-03-25 Thread Antoine Pitrou
Antoine Pitrou added the comment: > Agreed with nick's idea, the implicitly recreation of the context > managers would confuse users. Uh, why would it? That's exactly what I expect the decorator to do, and I was astonished to discover that it *doesn't*. --

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

2011-03-25 Thread Ray.Allen
Ray.Allen added the comment: Agreed with nick's idea, the implicitly recreation of the context managers would confuse users. How about removing the "generator must yield exactly one value" restriction of @contextlib.contextmanage? Then if I want a generator to be used as a common context man

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

2011-03-23 Thread Nick Coghlan
Nick Coghlan added the comment: > The former sounds like fixing the bug, the latter like removing > functionality. So yes, I prefer the former... The reason I'm reluctant is that it makes for a fundamental change in behaviour between the use of an @contextmanager definition as a context manage

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

2011-03-23 Thread Michael Foord
Michael Foord added the comment: The former sounds like fixing the bug, the latter like removing functionality. So yes, I prefer the former... -- ___ Python tracker ___ ___

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

2011-03-23 Thread Antoine Pitrou
Antoine Pitrou added the comment: > 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.context

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

2011-03-22 Thread Nick Coghlan
Nick Coghlan added the comment: 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 ca

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

2011-03-22 Thread Antoine Pitrou
New submission from Antoine Pitrou : If you add the following test to text_contextlib: diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py --- a/Lib/test/test_contextlib.py +++ b/Lib/test/test_contextlib.py @@ -363,6 +363,8 @@ class TestContextDecorator(unittest.Test