def __setitem__ ( self, key, value ):
        self_trait = getattr(self, 'trait', None)
        if self_trait == None:
            return list.__setitem__(self, key, value)
        try:
            removed = self[ key ]
        except:
            removed = []
        try:
            object   = self.object()
            validate = self.trait.item_trait.handler.validate
            name     = self.name

            if isinstance(key, slice):
                values = value
                try:
                    key = slice(*key.indices(len( self )))
                except (ValueError, TypeError):
                    raise TypeError('must assign sequence (not "%s") to slice' % (
                                    values.__class__.__name__ ))
                slice_len = max(0, (key.stop - key.start) // key.step)
                delta = len( values ) - slice_len
                if key.step != 1 and delta != 0:
                    raise ValueError(
                        'attempt to assign sequence of size %d to extended slice of size %d' % (
                        len( values ), slice_len
                    ))
                newlen = (len(self) + delta)
                if not (self_trait.minlen <= newlen <= self_trait.maxlen):
                    self.len_error( newlen )
                    return

                if validate is not None:
                    values = [ validate( object, name, value )
                               for value in values ]
                value = values
                if key.step == 1:
                    # FIXME: Bug-for-bug compatibility with old __setslice__ code.
                    # In this case, we return a TraitListEvent with an
                    # index=key.start and the removed and added lists as they
                    # are.
                    index = key.start
                else:
                    # Otherwise, we have an extended slice which was handled,
                    # badly, by __setitem__ before. In this case, we return the
                    # removed and added lists wrapped in another list.
                    index = key
                    values = [values]
                    removed = [removed]
            else:
                if validate is not None:
                    value = validate( object, name, value )

                values = [ value ]
                removed = [ removed ]
                delta = 0

                index = len( self ) + key if key < 0 else key

            list.__setitem__( self, key, value )
            if self.name_items is not None:
                if delta == 0:
                    try:
                        if removed == values:
                            return
                    except:
                        # Treat incomparable values as equal:
                        pass
                self._send_trait_items_event( self.name_items,
                    TraitListEvent( index, removed, values ) )

        except TraitError, excp:
            excp.set_prefix( 'Each element of the' )
            raise excp
dataset/ETHPy150Open enthought/traits/traits/trait_handlers.py/TraitListObject.__setitem__/operator `is` -> `==`