[New-bugs-announce] [issue9110] contextlib.ContextDecorator
report at bugs.python.org
Tue Jun 29 00:58:18 CEST 2010
New submission from Michael Foord <michael at voidspace.org.uk>:
Patch to add a ContextDecorator class to contextlib. This allows context managers that inherit from ContextDecorator (including using it as a mixin) to be used as decorators as well as context managers.
Context managers inheriting from ContextDecorator still have to implement __enter__ and __exit__ as normal. As the decorator behaviour is implemented using a with statement __exit__ retains its optional exception handling even when used as a decorator.
In addition contextlib.GeneratorContextManager, used to implement contextlib.contextmanager, inherits from ContextDecorator. Context managers created with contextlib.contextmanager can therefore be used as decorators too.
components: Library (Lib)
nosy: michael.foord, ncoghlan
stage: patch review
versions: Python 3.2
Added file: http://bugs.python.org/file17795/contextdecorator.patch
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce