Skip to content

Commit 616a234

Browse files
[use-implicit-booleaness] Micro-optimization if some messages are disabled
1 parent e3f32f1 commit 616a234

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pylint/checkers/refactoring/implicit_booleaness_checker.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,21 @@ def visit_unaryop(self, node: nodes.UnaryOp) -> None:
186186
"use-implicit-booleaness-not-comparison-to-zero",
187187
)
188188
def visit_compare(self, node: nodes.Compare) -> None:
189-
self._check_use_implicit_booleaness_not_comparison(node)
190-
self._check_compare_to_str_or_zero(node)
189+
if self.linter.is_message_enabled("use-implicit-booleaness-not-comparison"):
190+
self._check_use_implicit_booleaness_not_comparison(node)
191+
if self.linter.is_message_enabled(
192+
"use-implicit-booleaness-not-comparison-to-zero"
193+
) or self.linter.is_message_enabled(
194+
"use-implicit-booleaness-not-comparison-to-str"
195+
):
196+
self._check_compare_to_str_or_zero(node)
191197

192198
def _check_compare_to_str_or_zero(self, node: nodes.Compare) -> None:
193199
# note: astroid.Compare has the left most operand in node.left
194200
# while the rest are a list of tuples in node.ops
195201
# the format of the tuple is ('compare operator sign', node)
196202
# here we squash everything into `ops` to make it easier for processing later
197-
ops: list[tuple[str, nodes.NodeNG]] = [("", node.left)]
198-
ops.extend(node.ops)
203+
ops: list[tuple[str, nodes.NodeNG]] = [("", node.left), *node.ops]
199204
iter_ops = iter(ops)
200205
all_ops = list(itertools.chain(*iter_ops))
201206
for ops_idx in range(len(all_ops) - 2):

0 commit comments

Comments
 (0)