def declared_mixin(*bases):

    def wrapper(func):
        attrs = weakref.WeakKeyDictionary()
        def create_descriptor(name):
            def get_attr(cls):
                if cls not in attrs:
                    # Call func only once per class
                    attrs[cls] = return_locals(func)()
                return attrs[cls][name]
            get_attr.__name__ = name
            return declared_attr(get_attr)
        dict_ = {name: create_descriptor(name)
                 for name in func.func_code.co_varnames}
        dict_['__doc__'] = func.__doc__
        return type(func.__name__, bases, dict_)

    if len(bases)==1 and not isinstance(bases[0], type):
        # Short form (without bases) is used
        func = bases[0]
        bases = ()
        return wrapper(func)
    else:
        return wrapper
Create mix-in class with all assignments turned into methods decorated
dataset/ETHPy150Open SmartTeleMax/iktomi/iktomi/unstable/db/sqla/mixin.py/declared_mixin