def compare(left, right, compare_locs=False):
if type(left) != type(right):<EOL><INDENT>return False<EOL><DEDENT>if isinstance(left, ast.AST):<EOL><INDENT>for field in left._fields:<EOL><INDENT>if not compare(getattr(left, field), getattr(right, field)):<EOL><INDENT>return False<EOL><DEDENT><DEDENT>if compare_locs:<EOL><INDENT>for loc in left._locs:<EOL><INDENT>if getattr(left, loc) != getattr(right, loc):<EOL><INDENT>return False<EOL><DEDENT><DEDENT><DEDENT>return True<EOL><DEDENT>elif isinstance(left, list):<EOL><INDENT>if len(left) != len(right):<EOL><INDENT>return False<EOL><DEDENT>for left_elt, right_elt in zip(left, right):<EOL><INDENT>if not compare(left_elt, right_elt):<EOL><INDENT>return False<EOL><DEDENT><DEDENT>return True<EOL><DEDENT>else:<EOL><INDENT>return left == right<EOL><DEDENT>
An AST comparison function. Returns ``True`` if all fields in
``left`` are equal to fields in ``right``; if ``compare_locs`` is
true, all locations should match as well.