Exemplo n.º 1
0
    def _check_heterogenous_operators(self, node: ast.Compare) -> None:
        if len(node.ops) == 1:
            return

        prototype = compares.get_similar_operators(node.ops[0])

        for op in node.ops:
            if not isinstance(op, prototype):
                self.add_violation(HeterogenousCompareViolation(node))
                break
    def _check_heterogenous_operators(self, node: ast.Compare) -> None:
        if len(node.ops) == 1:
            return

        similar_operators = {
            ast.Gt: (ast.Gt, ast.GtE),
            ast.GtE: (ast.Gt, ast.GtE),
            ast.Lt: (ast.Lt, ast.LtE),
            ast.LtE: (ast.Lt, ast.LtE),
        }
        prototype = similar_operators.get(
            node.ops[0].__class__,
            node.ops[0].__class__,
        )

        for op in node.ops:
            if not isinstance(op, prototype):
                self.add_violation(HeterogenousCompareViolation(node))
                break