[New-bugs-announce] [issue32158] Suppress (and other contextlib context managers) should work as decorators (where appropriate)
Jason R. Coombs
report at bugs.python.org
Tue Nov 28 14:39:46 EST 2017
New submission from Jason R. Coombs <jaraco at jaraco.com>:
The contextlib docs explain why a decorator is nice:
> 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).
However, the built-in context managers that could readily supply this interface don't derive from DecoratorContext.
In jaraco.context, I [added decorator support by simply deriving from the two base classes](https://github.com/jaraco/jaraco.context/commit/5aa7b0bb222cff5009a2f0dc3ea49db9e7a6b71a#diff-efbedfbbcb7f61268cfeff04a32fa59d).
But it got me thinking - couldn't suppress (and possibly other) contextlib decorators support this usage out of the box?
If there's interest, I'll put together a patch with test.
----------
components: Library (Lib)
messages: 307155
nosy: jason.coombs
priority: normal
severity: normal
status: open
title: Suppress (and other contextlib context managers) should work as decorators (where appropriate)
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32158>
_______________________________________
More information about the New-bugs-announce
mailing list