def add(self, state):
        key = state.key
        # inline of self.__contains__
        if key in self._dict:
            try:
                existing_state = self._dict[key]
                if existing_state is not state:
                    o = existing_state.obj()
                    if o is not None:
                        raise sa_exc.InvalidRequestError(
                            "Can't attach instance "
                            "%s; another instance with key %s is already "
                            "present in this session." % (
                                orm_util.state_str(state), state.key))
                else:
                    return False
            except __HOLE__:
                pass
        self._dict[key] = state
        self._manage_incoming_state(state)
        return True
dataset/ETHPy150Open zzzeek/sqlalchemy/lib/sqlalchemy/orm/identity.py/WeakInstanceDict.add