def pop_n(stack, n):
    """Pop n items from the stack.

    If there are less than `n` items in the stack, raise an IndexError.

    .. note:: Code that catches the IndexError, will see the stack empty.

    The items are returned in pop-order: if stack is ``[1, 2, 3, 4]`` and `n`
    is 2, the result would be ``[4, 3]``.

    """
    if len(stack) < n:
        stack[:] = []
        raise IndexError('Popping too many items from the stack')
    items = stack[-n:]
    del stack[-n:]
    items.reverse()
    return items
