def is_descendant_of_type(ast_node, reference_type):
    """check if one of the ancestors is an instance of a type"""
    tmp = ast_node
    try:
        while tmp is not None:
            tmp = tmp.parent
            if isinstance(tmp, reference_type):
                return True
    except AttributeError:
        return False
