def __setitem__ ( self, key, value ):
        trait = getattr( self, 'trait', None )
        if trait is None:
            dict.__setitem__( self, key, value )
            return

        object = self.object()
        try:
            validate = trait.key_trait.handler.validate
            if validate is not None:
                key = validate( object, self.name, key )

        except TraitError, excp:
            excp.set_prefix( 'Each key of the' )
            raise excp

        try:
            validate = trait.value_handler.validate
            if validate is not None:
                value = validate( object, self.name, value )

            if self.name_items is not None:
                if key in self:
                    added   = None
                    old     = self[ key ]
                    changed = { key: old }
                else:
                    added   = { key: value }
                    changed = None

            dict.__setitem__( self, key, value )

            if self.name_items is not None:
                if added is None:
                    try:
                        if old == value:
                            return
                    except:
                        # Treat incomparable objects as unequal:
                        pass
                self._send_trait_items_event( self.name_items,
                    TraitDictEvent( added, changed ), trait.items_event() )

        except TraitError, excp:
            excp.set_prefix( 'Each value of the' )
            raise excp
dataset/ETHPy150Open enthought/traits/traits/trait_handlers.py/TraitDictObject.__setitem__/original