@classmethod
    def _listen(
            cls, event_key, raw=False, retval=False, propagate=False, **kw):
        target, identifier, fn = \
            event_key.dispatch_target, event_key.identifier, \
            event_key._listen_fn

        if ("before_configured", "after_configured") in identifier and \
                target is not mapperlib.Mapper:
            util.warn(
                "'before_configured' and 'after_configured' ORM events "
                "only invoke with the mapper() function or Mapper class "
                "as the target.")

        if not raw or not retval:
            if not raw:
                meth = getattr(cls, identifier)
                try:
                    target_index = \
                        inspect_getargspec(meth)[0].index('target') - 1
                except ValueError:
                    target_index = None

            def wrap(*arg, **kw):
                if not raw and target_index is not None:
                    arg = list(arg)
                    arg[target_index] = arg[target_index].obj()
                if not retval:
                    fn(*arg, **kw)
                    return interfaces.EXT_CONTINUE
                else:
                    return fn(*arg, **kw)
            event_key = event_key.with_wrapper(wrap)

        if propagate:
            for mapper in target.self_and_descendants:
                event_key.with_dispatch_target(mapper).base_listen(
                    propagate=True, **kw)
        else:
            event_key.base_listen(**kw)
dataset/ETHPy150Open zzzeek/sqlalchemy/lib/sqlalchemy/orm/events.py/MapperEvents._listen/swapped operands of `in`