summaryrefslogtreecommitdiff
path: root/pylint/checkers/variables.py
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2022-06-18 10:14:53 +0200
committerGitHub <noreply@github.com>2022-06-18 10:14:53 +0200
commita52edfde6690f8478578019a6bc41de7206aa63d (patch)
tree33aaf1fd5225412267bc3aeca14f7f17d8453399 /pylint/checkers/variables.py
parentcac381d7e316aec5f7dfb545d2c91835658f2270 (diff)
downloadpylint-git-a52edfde6690f8478578019a6bc41de7206aa63d.tar.gz
Fix ``undefined-loop-variable`` and ``undefined-variable`` with ``useless-suppression`` (#6971)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'pylint/checkers/variables.py')
-rw-r--r--pylint/checkers/variables.py38
1 files changed, 12 insertions, 26 deletions
diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py
index 13d289d72..7684d1ac2 100644
--- a/pylint/checkers/variables.py
+++ b/pylint/checkers/variables.py
@@ -1082,15 +1082,6 @@ class VariablesChecker(BaseChecker):
"""This is a queue, last in first out."""
self._postponed_evaluation_enabled = False
- def open(self) -> None:
- """Called when loading the checker."""
- self._is_undefined_variable_enabled = self.linter.is_message_enabled(
- "undefined-variable"
- )
- self._is_undefined_loop_variable_enabled = self.linter.is_message_enabled(
- "undefined-loop-variable"
- )
-
def leave_for(self, node: nodes.For) -> None:
self._store_type_annotation_names(node)
@@ -1353,8 +1344,7 @@ class VariablesChecker(BaseChecker):
return
self._undefined_and_used_before_checker(node, stmt)
- if self._is_undefined_loop_variable_enabled:
- self._loopvar_name(node)
+ self._loopvar_name(node)
@utils.only_required_for_messages("redefined-outer-name")
def visit_excepthandler(self, node: nodes.ExceptHandler) -> None:
@@ -1411,23 +1401,19 @@ class VariablesChecker(BaseChecker):
# we have not found the name, if it isn't a builtin, that's an
# undefined name !
- if (
- self._is_undefined_variable_enabled
- and not (
- node.name in nodes.Module.scope_attrs
- or utils.is_builtin(node.name)
- or node.name in self.linter.config.additional_builtins
- or (
- node.name == "__class__"
- and any(
- i.is_method()
- for i in node.node_ancestors()
- if isinstance(i, nodes.FunctionDef)
- )
+ if not (
+ node.name in nodes.Module.scope_attrs
+ or utils.is_builtin(node.name)
+ or node.name in self.linter.config.additional_builtins
+ or (
+ node.name == "__class__"
+ and any(
+ i.is_method()
+ for i in node.node_ancestors()
+ if isinstance(i, nodes.FunctionDef)
)
)
- and not utils.node_ignores_exception(node, NameError)
- ):
+ ) and not utils.node_ignores_exception(node, NameError):
self.add_message("undefined-variable", args=node.name, node=node)
def _should_node_be_skipped(