@@ -186,16 +186,21 @@ def visit_unaryop(self, node: nodes.UnaryOp) -> None:
186
186
"use-implicit-booleaness-not-comparison-to-zero" ,
187
187
)
188
188
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 )
191
197
192
198
def _check_compare_to_str_or_zero (self , node : nodes .Compare ) -> None :
193
199
# note: astroid.Compare has the left most operand in node.left
194
200
# while the rest are a list of tuples in node.ops
195
201
# the format of the tuple is ('compare operator sign', node)
196
202
# 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 ]
199
204
iter_ops = iter (ops )
200
205
all_ops = list (itertools .chain (* iter_ops ))
201
206
for ops_idx in range (len (all_ops ) - 2 ):
0 commit comments