From a192f3a1a4883e05bb0f5564dae86eb422c9860b Mon Sep 17 00:00:00 2001 From: "Mr. Senko" Date: Fri, 23 Mar 2018 15:55:08 +0200 Subject: [PATCH] Suppress not-an-iterable message for model_utils.managers. Fixes #117 --- pylint_django/augmentations/__init__.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pylint_django/augmentations/__init__.py b/pylint_django/augmentations/__init__.py index 924f7c08..b1f3fd33 100644 --- a/pylint_django/augmentations/__init__.py +++ b/pylint_django/augmentations/__init__.py @@ -11,7 +11,7 @@ from pylint.checkers.newstyle import NewStyleConflictChecker from pylint.checkers.variables import VariablesChecker from pylint.__pkginfo__ import numversion as PYLINT_VERSION -from pylint.checkers.typecheck import TypeChecker +from pylint.checkers.typecheck import IterableChecker, TypeChecker from pylint.checkers.variables import ScopeConsumer from pylint_plugin_utils import augment_visit, suppress_message @@ -676,6 +676,17 @@ def wrap_func(*args, **kwargs): return wrap_func +def is_model_utils_manager(node): + """Checks that node is derivative of model_utils.managers classes.""" + try: + # try to get the model manager node, i.e. 'objects' + manager = node.func.expr + except: # noqa: E722, pylint: disable=bare-except + return False + + return isinstance(manager, Attribute) and manager.attrname == 'objects' + + # The names of some visit functions changed in this commit: # https://bitbucket.org/logilab/pylint/commits/c94ee95abaa5737f13b91626fe321150c0ddd140 @@ -795,3 +806,6 @@ def apply_augmentations(linter): VariablesChecker.leave_module = wrap(current_leave_module, ignore_import_warnings_for_related_fields) # VariablesChecker.leave_module is now wrapped # else VariablesChecker.leave_module is already wrapped + + # supress not-an-iterable for model_utils.managers + suppress_message(linter, IterableChecker._check_iterable, 'not-an-iterable', is_model_utils_manager)