'Set a value on the given InstanceState.'

def set(self, state, dict_, value, initiator, passive=PASSIVE_OFF, check_old=None, pop=False):

    if self.dispatch._active_history:
        old = self.get(state, dict_, passive=(PASSIVE_ONLY_PERSISTENT | NO_AUTOFLUSH))
    else:
        old = self.get(state, dict_, passive=PASSIVE_NO_FETCH)
    if ((check_old is not None) and (old is not PASSIVE_NO_RESULT) and (check_old is not old)):
        if pop:
            return
        else:
            raise ValueError(("Object    %s    not    associated    with    %s    on    attribute    '%s'" % (instance_str(check_old), state_str(state), self.key)))
    value = self.fire_replace_event(state, dict_, value, old, initiator)
    dict_[self.key] = value
