def ancestors(node):
    '''
    Returns the list of all nodes dominating the given tree node.
    This method will not work with leaf nodes, since there is no way
    to recover the parent.
    '''
    results = []
    try:
        current = node.parent()
    except __HOLE__:
        # if node is a leaf, we cannot retrieve its parent
        return results
    while current:
        results.append(current)
        current = current.parent()
    return results
dataset/ETHPy150Open nltk/nltk/nltk/tgrep.py/ancestors