import ast


def find_parent_statement(node):
    """Traverse upwards through the ast until we hit a statement node"""
    while not isinstance(node, (ast.stmt, ast.Module)):
        node = node.parent
    return node