@@ -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