def handle_index(l, index):
    """Handle index.

    If the index is negative, convert it. If the index is out of range, raise
    an IndexError.
    """
    # convert negative indices to positive ones
    if index < 0:
        # len(l) has always type 'int64'
        # while index can be an signed/unsigned integer
        index = type(index)(len(l) + index)
    # check that the index is in range
    if not (0 <= index < len(l)):
        raise IndexError("list index out of range")
    return index