'Set an HDU to the `HDUList`, indexed by number or name.'

def __setitem__(self, key, hdu):

    _key = self._positive_index_of(key)
    if isinstance(hdu, (slice, list)):
        if _is_int(_key):
            raise ValueError('An    element    in    the    HDUList    must    be    an    HDU.')
        for item in hdu:
            if (not isinstance(item, _BaseHDU)):
                raise ValueError('{}    is    not    an    HDU.'.format(item))
    elif (not isinstance(hdu, _BaseHDU)):
        raise ValueError('{}    is    not    an    HDU.'.format(hdu))
    try:
        self._try_while_unread_hdus(super(HDUList, self).__setitem__, _key, hdu)
    except IndexError:
        raise IndexError('Extension    {}    is    out    of    bound    or    not    found.'.format(key))
    self._resize = True
    self._truncate = False
