Skip to content

Commit

Permalink
Squash VariablesChecker3k into the general checker class
Browse files Browse the repository at this point in the history
  • Loading branch information
PCManticore committed Sep 23, 2019
1 parent b49c281 commit 454c9ba
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions pylint/checkers/variables.py
Expand Up @@ -719,6 +719,8 @@ def leave_module(self, node):
"""leave module: check globals
"""
assert len(self._to_consume) == 1

self._check_metaclasses(node)
not_consumed = self._to_consume.pop().to_consume
# attempt to check for __all__ if defined
if "__all__" in node.locals:
Expand Down Expand Up @@ -833,6 +835,8 @@ def visit_functiondef(self, node):

def leave_functiondef(self, node):
"""leave function: check function's locals are consumed"""
self._check_metaclasses(node)

if node.type_comment_returns:
self._store_type_annotation_node(node.type_comment_returns)
if node.type_comment_args:
Expand Down Expand Up @@ -1181,6 +1185,18 @@ def visit_assign(self, node):
except astroid.InferenceError:
return

# listcomp have now also their scope
def visit_listcomp(self, node):
"""visit dictcomp: update consumption analysis variable
"""
self._to_consume.append(NamesConsumer(node, "comprehension"))

def leave_listcomp(self, _):
"""leave dictcomp: update consumption analysis variable
"""
# do not check for not used locals here
self._to_consume.pop()

def leave_assign(self, node):
self._store_type_annotation_names(node)

Expand Down Expand Up @@ -1890,31 +1906,6 @@ def _check_imports(self, not_consumed):
self.add_message("unused-import", args=msg, node=stmt)
del self._to_consume


class VariablesChecker3k(VariablesChecker):
"""Modified variables checker for 3k"""

# listcomp have now also their scope

def visit_listcomp(self, node):
"""visit dictcomp: update consumption analysis variable
"""
self._to_consume.append(NamesConsumer(node, "comprehension"))

def leave_listcomp(self, _):
"""leave dictcomp: update consumption analysis variable
"""
# do not check for not used locals here
self._to_consume.pop()

def leave_functiondef(self, node):
self._check_metaclasses(node)
super(VariablesChecker3k, self).leave_functiondef(node)

def leave_module(self, node):
self._check_metaclasses(node)
super(VariablesChecker3k, self).leave_module(node)

def _check_metaclasses(self, node):
""" Update consumption analysis for metaclasses. """
consumed = [] # [(scope_locals, consumed_key)]
Expand Down Expand Up @@ -1973,4 +1964,4 @@ def _check_classdef_metaclasses(self, klass, parent_node):

def register(linter):
"""required method to auto register this checker"""
linter.register_checker(VariablesChecker3k(linter))
linter.register_checker(VariablesChecker(linter))

0 comments on commit 454c9ba

Please sign in to comment.