'Associate a SQL type with this mutable Python type.
This establishes listeners that will detect ORM mappings against
the given type, adding mutation event trackers to those mappings.
The type is returned, unconditionally as an instance, so that
:meth:`.as_mutable` can be used inline::
Table(\'mytable\', metadata,
Column(\'id\', Integer, primary_key=True),
Column(\'data\', MyMutableType.as_mutable(PickleType))
Note that the returned type is always an instance, even if a class
is given, and that only columns which are declared specifically with
that type instance receive additional instrumentation.
To associate a particular mutable type with all occurrences of a
particular type, use the :meth:`.Mutable.associate_with` classmethod
of the particular :class:`.Mutable` subclass to establish a global
association.
.. warning::
The listeners established by this method are *global*
to all mappers, and are *not* garbage collected.   Only use
:meth:`.as_mutable` for types that are permanent to an application,
not with ad-hoc types else this will cause unbounded growth
in memory usage.'

@classmethod
def as_mutable(cls, sqltype):

    sqltype = types.to_instance(sqltype)
    def listen_for_type(mapper, class_):
        for prop in mapper.column_attrs:
            if (prop.columns[0].type is sqltype):
                cls.associate_with_attribute(getattr(class_, prop.key))
    event.listen(mapper, 'mapper_configured', listen_for_type)
    return sqltype
