Exemple #1
0
def find_if_x_retbool_else_retbool(node):
    """Finds simplifiable if condition"""
    return (
        isinstance(node, ast.If)
        and isinstance(node.body[0], ast.Return)
        and h.is_boolean(node.body[0].value)
        and h.has_else(node)
        and isinstance(node.orelse[0], ast.Return)
        and h.is_boolean(node.orelse[0].value)
    )
Exemple #2
0
def find_equals_true_or_false(node):
    """Finds equals true or false"""
    return (
        isinstance(node, ast.Compare)
        and len(node.ops) == 1
        and isinstance(node.ops[0], ast.Eq)
        and any(h.is_boolean(n) for n in node.comparators)
    )
Exemple #3
0
def find_if_x_retbool_else_retbool(node):
    """Finds simplifiable if condition"""
    return (isinstance(node, ast.If) and isinstance(node.body[0], ast.Return)
            and h.is_boolean(node.body[0].value) and h.has_else(node)
            and isinstance(node.orelse[0], ast.Return)
            and h.is_boolean(node.orelse[0].value))
Exemple #4
0
def find_equals_true_or_false(node):
    """Finds equals true or false"""
    return (isinstance(node, ast.Compare) and len(node.ops) == 1
            and isinstance(node.ops[0], ast.Eq)
            and any(h.is_boolean(n) for n in node.comparators))