Skip to content

Commit 5b00ea2

Browse files
committed
Suppress not-an-iterable message for model_utils.managers. Fixes #117
1 parent 4d56bb5 commit 5b00ea2

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

pylint_django/augmentations/__init__.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pylint.checkers.newstyle import NewStyleConflictChecker
1212
from pylint.checkers.variables import VariablesChecker
1313
from pylint.__pkginfo__ import numversion as PYLINT_VERSION
14-
from pylint.checkers.typecheck import TypeChecker
14+
from pylint.checkers.typecheck import IterableChecker, TypeChecker
1515
from pylint.checkers.variables import ScopeConsumer
1616

1717
from pylint_plugin_utils import augment_visit, suppress_message
@@ -462,6 +462,29 @@ def is_manager_attribute(node):
462462
return _attribute_is_magic(node, MANAGER_ATTRS.union(QS_ATTRS), parents)
463463

464464

465+
def is_model_manager(node):
466+
"""Checks that node is an attribute named `objects` which usually represents
467+
468+
This function fixes issues #117 and #144.
469+
"""
470+
try:
471+
# try to get the model manager node, i.e. 'objects'
472+
manager = node.func.expr
473+
except: # noqa: E722, pylint: disable=bare-except
474+
return False
475+
476+
parents = ('django.db.models.manager.Manager',
477+
'.Manager',
478+
'django.db.models.query.QuerySet',
479+
'.QuerySet',
480+
'model_utils.managers.InheritanceManager',
481+
'model_utils.managers.QueryManager',
482+
'model_utils.managers.SoftDeletableManager',
483+
)
484+
return _attribute_is_magic(manager, ['objects'], parents)
485+
#return isinstance(manager, Attribute) and manager.attrname == 'objects'
486+
487+
465488
def is_admin_attribute(node):
466489
"""Checks that node is attribute of BaseModelAdmin."""
467490
parents = ('django.contrib.admin.options.BaseModelAdmin',
@@ -795,3 +818,6 @@ def apply_augmentations(linter):
795818
VariablesChecker.leave_module = wrap(current_leave_module, ignore_import_warnings_for_related_fields)
796819
# VariablesChecker.leave_module is now wrapped
797820
# else VariablesChecker.leave_module is already wrapped
821+
822+
# supress not-an-iterable for model_utils.managers
823+
suppress_message(linter, IterableChecker._check_iterable, 'not-an-iterable', is_model_manager)

0 commit comments

Comments
 (0)