Compare if two nodes are equal.

def cmp_ast(node1, node2):
    '''
    Compare if two nodes are equal.
    '''

    if type(node1) != type(node2):
        return False

    if isinstance(node1, (list, tuple)):
        if len(node1) != len(node2):
            return False

        for left, right in zip(node1, node2):
            if not cmp_ast(left, right):
                return False

    elif isinstance(node1, ast.AST):
        for field in node1._fields:
            left = getattr(node1, field, Undedined)
            right = getattr(node2, field, Undedined)

            if not cmp_ast(left, right):
                return False
    else:
        return node1 == node2

    return True