summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2023-05-02 23:17:04 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2023-05-03 22:01:26 +0200
commitbe15ae44eef293f35529e2522760e758b3c81238 (patch)
tree2f642379428693389fe9bc2b04af03fb8b578255
parent55504c5926d8159ff73a9c2167f60e3b467765f0 (diff)
downloadpylint-git-be15ae44eef293f35529e2522760e758b3c81238.tar.gz
[use-implicit-booleaness] Micro-optimization if some messages are disabled
-rw-r--r--pylint/checkers/refactoring/implicit_booleaness_checker.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/pylint/checkers/refactoring/implicit_booleaness_checker.py b/pylint/checkers/refactoring/implicit_booleaness_checker.py
index 67914c1e6..5b91990b0 100644
--- a/pylint/checkers/refactoring/implicit_booleaness_checker.py
+++ b/pylint/checkers/refactoring/implicit_booleaness_checker.py
@@ -186,16 +186,21 @@ class ImplicitBooleanessChecker(checkers.BaseChecker):
"use-implicit-booleaness-not-comparison-to-zero",
)
def visit_compare(self, node: nodes.Compare) -> None:
- self._check_use_implicit_booleaness_not_comparison(node)
- self._check_compare_to_str_or_zero(node)
+ if self.linter.is_message_enabled("use-implicit-booleaness-not-comparison"):
+ self._check_use_implicit_booleaness_not_comparison(node)
+ if self.linter.is_message_enabled(
+ "use-implicit-booleaness-not-comparison-to-zero"
+ ) or self.linter.is_message_enabled(
+ "use-implicit-booleaness-not-comparison-to-str"
+ ):
+ self._check_compare_to_str_or_zero(node)
def _check_compare_to_str_or_zero(self, node: nodes.Compare) -> None:
# note: astroid.Compare has the left most operand in node.left
# while the rest are a list of tuples in node.ops
# the format of the tuple is ('compare operator sign', node)
# here we squash everything into `ops` to make it easier for processing later
- ops: list[tuple[str, nodes.NodeNG]] = [("", node.left)]
- ops.extend(node.ops)
+ ops: list[tuple[str, nodes.NodeNG]] = [("", node.left), *node.ops]
iter_ops = iter(ops)
all_ops = list(itertools.chain(*iter_ops))
for ops_idx in range(len(all_ops) - 2):