def with_metaclass(meta, *bases):
    class metaclass(meta):
        def __new__(cls, name, this_bases, d):
            return meta(name, bases, d)
    return type.__new__(metaclass, 'temporary_class', (), {})

#=============================================================================
Python 2/3 cross-compatible way to use a metclass
dataset/ETHPy150Open KristianOellegaard/django-hvad/hvad/compat.py/with_metaclass