From 1524cdf7dc79a038f557752b36b232dbf32b7149 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 16 Aug 2021 14:43:16 +0200 Subject: [PATCH] Refactor existing code - code_style extension --- pylint/extensions/code_style.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/pylint/extensions/code_style.py b/pylint/extensions/code_style.py index 9fff904b90..3f400fd18e 100644 --- a/pylint/extensions/code_style.py +++ b/pylint/extensions/code_style.py @@ -53,11 +53,13 @@ def visit_dict(self, node: nodes.Dict) -> None: @check_messages("consider-using-tuple") def visit_for(self, node: nodes.For) -> None: - self._check_inplace_defined_list(node) + if isinstance(node.iter, nodes.List): + self.add_message("consider-using-tuple", node=node.iter) @check_messages("consider-using-tuple") def visit_comprehension(self, node: nodes.Comprehension) -> None: - self._check_inplace_defined_list(node) + if isinstance(node.iter, nodes.List): + self.add_message("consider-using-tuple", node=node.iter) def _check_dict_consider_namedtuple_dataclass(self, node: nodes.Dict) -> None: """Check if dictionary values can be replaced by Namedtuple or Dataclass.""" @@ -133,13 +135,6 @@ def _check_dict_consider_namedtuple_dataclass(self, node: nodes.Dict) -> None: self.add_message("consider-using-namedtuple-or-dataclass", node=node) return - def _check_inplace_defined_list( - self, node: Union[nodes.For, nodes.Comprehension] - ) -> None: - """Check if in-place defined list can be replaced by a tuple.""" - if isinstance(node.iter, nodes.List): - self.add_message("consider-using-tuple", node=node.iter) - def register(linter: PyLinter) -> None: linter.register_checker(CodeStyleChecker(linter))