From 124fb117987a4361dd1536cbcf1ec2cd41b037d4 Mon Sep 17 00:00:00 2001 From: David Allouche Date: Wed, 10 Jan 2018 23:18:35 +0100 Subject: Enable pylint to support decorator.contextmanager Using decorator.contextmanager trigger the pylint error E1129 (not-context-manager). Pylint has a configuration option for this: # List of decorators that produce context managers, such as # contextlib.contextmanager. Add to this list to register other decorators that # produce valid context managers. contextmanager-decorators=contextlib.contextmanager,decorator.contextmanager But the current implementation of decorator.contextmanager prevents this from working. Changing contextmanager to be a simple function fixes the issue. --- src/decorator.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/decorator.py b/src/decorator.py index 788f4bb..e213bc3 100644 --- a/src/decorator.py +++ b/src/decorator.py @@ -298,7 +298,12 @@ elif n_args == 4: # (self, gen, args, kwds) Python 3.5 return _GeneratorContextManager.__init__(self, g, a, k) ContextManager.__init__ = __init__ -contextmanager = decorator(ContextManager) +_contextmanager = decorator(ContextManager) + + +def contextmanager(func): + # Enable Pylint config: contextmanager-decorators=decorator.contextmanager + return _contextmanager(func) # ############################ dispatch_on ############################ # -- cgit v1.2.1