[issue9110] contextlib.ContextDecorator
Nick Coghlan
report at bugs.python.org
Sat Jul 10 10:16:46 CEST 2010
Nick Coghlan <ncoghlan at gmail.com> added the comment:
One thing that Jack's confusion above does suggest to me is that we should mention in the *ContextDecorator* documentation that it is automatically applied to the context managers created when you use @contextmanager. A lot of people familiar with contextmanager are just going to read the docs for the new toy, so may miss the fact that we have added __call__ support to GeneratorContextManager.
As far as use cases go, this change is just syntactic sugar for any construct of the following form:
def f():
with cm():
# Do stuff
ContextDecorator lets you instead write:
@cm
def f():
# Do stuff
It makes it clear that the CM applies to the whole function, rather than just a piece of it (and saving an indentation level is nice, too).
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9110>
_______________________________________
More information about the Python-bugs-list
mailing list