From b05ac51ad2e3785b6b9b071b8cb241993c914105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Sat, 18 Jun 2022 09:32:24 +0200 Subject: [PATCH] Pin ``colorama`` to lowest supported version (#6970) --- doc/whatsnew/2/2.14/full.rst | 2 ++ pylint/checkers/variables.py | 38 ++++++++++++------------------------ setup.cfg | 2 +- 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/doc/whatsnew/2/2.14/full.rst b/doc/whatsnew/2/2.14/full.rst index 8bd3ada5f2..2f6819b847 100644 --- a/doc/whatsnew/2/2.14/full.rst +++ b/doc/whatsnew/2/2.14/full.rst @@ -14,6 +14,8 @@ Release date: TBA Closes #2270 +* Allow suppressing ``undefined-loop-variable`` and ``undefined-variable`` without raising ``useless-suppression``. + * Fixed false positive for ``undefined-variable`` for ``__class__`` in inner methods. Closes #4032 diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py index 9027b65887..75a064d606 100644 --- a/pylint/checkers/variables.py +++ b/pylint/checkers/variables.py @@ -1081,15 +1081,6 @@ def __init__(self, linter=None): """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 @@ def visit_name(self, node: nodes.Name) -> None: 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 @@ def _undefined_and_used_before_checker( # 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( diff --git a/setup.cfg b/setup.cfg index ebe3815fe9..7b2c954fd7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -52,7 +52,7 @@ install_requires = mccabe>=0.6,<0.8 tomli>=1.1.0;python_version<"3.11" tomlkit>=0.10.1 - colorama;sys_platform=="win32" + colorama>=0.4.5;sys_platform=="win32" typing-extensions>=3.10.0;python_version<"3.10" python_requires = >=3.7.2