Skip to content

augmentation: use ScopeConsumer instead an array #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pylint_django/augmentations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from astroid.scoped_nodes import Class as ScopedClass, Module
from pylint.__pkginfo__ import numversion as PYLINT_VERSION
from pylint.checkers.typecheck import TypeChecker
from pylint.checkers.variables import ScopeConsumer
from pylint_django.utils import node_is_subclass, PY3
from pylint_django.compat import inferred
from pylint_plugin_utils import augment_visit, suppress_message
Expand Down Expand Up @@ -280,22 +281,22 @@ def ignore_import_warnings_for_related_fields(orig_method, self, node):
form 'from django.db.models import OneToOneField' raise an unused-import
warning
"""
to_consume = self._to_consume[0] # pylint: disable=W0212
consumer = self._to_consume[0] # pylint: disable=W0212
# we can disable this warning ('Access to a protected member _to_consume of a client class')
# as it's not actually a client class, but rather, this method is being monkey patched
# onto the class and so the access is valid

new_things = {}

iterat = to_consume[0].items if PY3 else to_consume[0].iteritems
iterat = consumer.to_consume.items if PY3 else consumer.to_consume.iteritems
for name, stmts in iterat():
if isinstance(stmts[0], ImportFrom):
if any([n[0] in ('ForeignKey', 'OneToOneField') for n in stmts[0].names]):
continue
new_things[name] = stmts

new_consume = (new_things,) + to_consume[1:]
self._to_consume = [new_consume] # pylint: disable=W0212
consumer._atomic = ScopeConsumer(new_things, consumer.consumed, consumer.scope_type) # pylint: disable=W0212
self._to_consume = [consumer] # pylint: disable=W0212

return orig_method(self, node)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

_install_requires = [
'pylint-plugin-utils>=0.2.1',
'pylint>=1.8'
'pylint>=1.8.2'
]


Expand Down