[New-bugs-announce] [issue9110] contextlib.ContextDecorator

Michael Foord 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.

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 <report at bugs.python.org>

More information about the New-bugs-announce mailing list