def canonicalize(node):
    """
    Rewrites the AST so that all comparisons are in a
    canonical order. This allows the expressions:
        gender is 'Male' / 'Male' is gender

    to be transformed into the same form. This makes
    refactoring expressions order independent.
    """
    def replace_func(pattern, n):
        l_literal = isinstance(n.left, ast.Literal)
        r_literal = isinstance(n.right, ast.Literal)

        # Always put the literal on the left
        if not l_literal and r_literal:
            n.reverse()

        elif l_literal and r_literal:
            # Put static values on the right
            if n.left.static and not n.right.static:
                n.reverse()

            # Put the literals in order (both non-static)
            elif not n.left.static and not n.right.static and n.left.value > n.right.value:
                n.reverse()

            # Put the literals in order (both static)
            elif n.left.static and n.right.static and n.right.value > n.left.value:
                n.reverse()

    p = SimplePattern("types:CompareOperator")
    return tile(node, [p], replace_func)
dataset/ETHPy150Open armon/pypred/pypred/compare.py/canonicalize/swapped operands of `>`