def template(class_T):
    """Factory function to create subclasses of class_T."""


class Foo(class_T):

    def fun(self):
        print('%s.fun()' % self.__class__.__name__)
Foo.__name__ += '_' + class_T.__name__
return Foo


class Base1:

    def bar(self):
        print('Base1.bar()')


class Base2:

    def bar(self):
        print('Base2.bar()')
Foo_Base1 = template(Base1)
print('Foo_Base1 base classes: {}'.format(Foo_Base1.__bases__))
Foo_Base2 = template(Base2)
print('Foo_Base2 base classes: {}'.format(Foo_Base2.__bases__))
subclass1 = Foo_Base1()
subclass1.fun()
subclass1.bar()
subclass2 = Foo_Base2()
subclass2.fun()
subclass2.bar()
Метакласс для параметризации наследования