def equality_rewrite(node, name, expr, assumed_result):
    # Get the literal and static compare values
    static_value = expr.right.value
    is_static = expr.right.static

    # Do we 'know' the value to be something
    # specific, or can we just eliminate a possible value.
    if expr.type in EQUALITY:
        known = assumed_result
    else:
        known = not assumed_result

    # Replace function to handle AST re-writes
    def replace_func(pattern, node):
        # Do the static comparison
        static_match = node.right.value == static_value
        is_static_node = node.right.static

        # If we are refactoring equality on a static
        # variable, then we can statically perform the comparisons
        # and do more aggressive rewrites of the AST.
        const = None
        if known and is_static and is_static_node:
            if node.type in EQUALITY:
                const = static_match
            else:
                const = not static_match

        # If we are refactoring equality on a non-static
        # variable, then we have a limit set of rewrites.
        # for example, if a = b, then a = c could also be true,
        # since b = c is possible.
        elif static_match:
            if node.type in EQUALITY:
                const = known
            else:
                const = not known

        # If we can't do a rewrite, just skip this node
        return ast.Constant(const) if const is not None else None

    # Tile to replace
    pattern = SimplePattern("types:CompareOperator AND ops:=,!=,is", ASTPattern(expr.left))
    return tile(node, [pattern], replace_func)
dataset/ETHPy150Open armon/pypred/pypred/compare.py/equality_rewrite/original