New submission from Michael Foord <mich...@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. ---------- assignee: michael.foord components: Library (Lib) files: contextdecorator.patch keywords: patch messages: 108877 nosy: michael.foord, ncoghlan priority: normal severity: normal stage: patch review status: open title: contextlib.ContextDecorator type: behavior versions: Python 3.2 Added file: http://bugs.python.org/file17795/contextdecorator.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue9110> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com