def inside(l1, l2):
    """Test whether l1 is a successor of l2.

    l1 is a successor of l2 if l2 is in the chain of parents of l1 or l2
    is l1.

    """
    while l1 is not None:
        if l1 is l2:
            return True
        l1 = getattr(l1, '__parent__', None)
    return False