예제 #1
0
    def _check_unpythonic_compare(self, node: ast.Compare) -> None:
        all_nodes = [node.left, *node.comparators]

        for index, compare in enumerate(all_nodes):
            if not isinstance(compare, ast.Call):
                continue
            if functions.given_function_called(compare, {'len'}):
                ps = index - len(all_nodes) + 1
                if not _is_correct_len(node.ops[ps], node.comparators[ps]):
                    self.add_violation(UselessLenCompareViolation(node))
예제 #2
0
 def _check_useless_len(self, node: AnyIf) -> None:
     if isinstance(node.test, ast.Call):
         if given_function_called(node.test, {'len'}):
             self.add_violation(UselessLenCompareViolation(node))