Skip to content

Commit

Permalink
Suppress not-an-iterable message for model_utils.managers. Fixes #117
Browse files Browse the repository at this point in the history
  • Loading branch information
atodorov committed Mar 23, 2018
1 parent 23394dc commit a192f3a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pylint_django/augmentations/__init__.py
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)

0 comments on commit a192f3a

Please sign in to comment.