def with_metaclass(meta, *bases):
class metaclass(meta):<EOL><INDENT>"""<STR_LIT>"""<EOL>__call__ = type.__call__<EOL>__init__ = type.__init__<EOL>def __new__(cls, name, this_bases, d):<EOL><INDENT>if this_bases is None:<EOL><INDENT>return type.__new__(cls, name, (), d)<EOL><DEDENT>return meta(name, bases, d)<EOL><DEDENT><DEDENT>return metaclass('<STR_LIT>', None, {})<EOL>
Function from jinja2/_compat.py. License: BSD.

Usage::

    class BaseForm(object):
        pass

    class FormType(type):
        pass

    class Form(with_metaclass(FormType, BaseForm)):
        pass

This requires a bit of explanation: the basic idea is to make a
dummy metaclass for one level of class instantiation that replaces
itself with the actual metaclass.  Because of internal type checks
we also need to make sure that we downgrade the custom metaclass
for one level to something closer to type (that's why __call__ and
__init__ comes back from type etc.).

This has the advantage over six.with_metaclass of not introducing
dummy classes into the final MRO.