'Establish this type as a mutation listener for the given
mapped descriptor.'

@classmethod
def _listen_on_attribute(cls, attribute, coerce, parent_cls):

    key = attribute.key
    if (parent_cls is not attribute.class_):
        return
    parent_cls = attribute.class_
    def load(state, *args):
        "Listen    for    objects    loaded    or    refreshed.\n\n                                                Wrap    the    target    data    member's    value    with\n                                                ``Mutable``.\n\n                                                "
        val = state.dict.get(key, None)
        if (val is not None):
            if coerce:
                val = cls.coerce(key, val)
                state.dict[key] = val
            val._parents[state.obj()] = key
    def set(target, value, oldvalue, initiator):
        'Listen    for    set/replace    events    on    the    target\n                                                data    member.\n\n                                                Establish    a    weak    reference    to    the    parent    object\n                                                on    the    incoming    value,    remove    it    for    the    one\n                                                outgoing.\n\n                                                '
        if (value is oldvalue):
            return value
        if (not isinstance(value, cls)):
            value = cls.coerce(key, value)
        if (value is not None):
            value._parents[target.obj()] = key
        if isinstance(oldvalue, cls):
            oldvalue._parents.pop(target.obj(), None)
        return value
    def pickle(state, state_dict):
        val = state.dict.get(key, None)
        if (val is not None):
            if ('ext.mutable.values' not in state_dict):
                state_dict['ext.mutable.values'] = []
            state_dict['ext.mutable.values'].append(val)
    def unpickle(state, state_dict):
        if ('ext.mutable.values' in state_dict):
            for val in state_dict['ext.mutable.values']:
                val._parents[state.obj()] = key
    event.listen(parent_cls, 'load', load, raw=True, propagate=True)
    event.listen(parent_cls, 'refresh', load, raw=True, propagate=True)
    event.listen(attribute, 'set', set, raw=True, retval=True, propagate=True)
    event.listen(parent_cls, 'pickle', pickle, raw=True, propagate=True)
    event.listen(parent_cls, 'unpickle', unpickle, raw=True, propagate=True)
