I want SuperClass12
to inherit from SuperClass1
and SuperClass2
:
def getClass1():
class MyMetaClass1(type):
def __new__(cls, name, bases, dct):
print dct.get("Attr","")+"Meta1"
return super(MyMetaClass1, cls).__new__(cls, name, bases, dct)
return MyMetaClass1
def getClass2():
class MyMetaClass2(type):
def __new__(cls, name, bases, dct):
print dct.get("Attr","")+"Meta2"
return super(MyMetaClass2, cls).__new__(cls, name, bases, dct)
return MyMetaClass2
class SuperClass1():
__metaclass__ = getClass1()
def fun1(self):
pass
class SuperClass2():
__metaclass__ = getClass2()
def fun2(self):
pass
class MyClass1(SuperClass1):
Attr = "MC1"
class MyClass2(SuperClass2):
Attr = "MC2"
def getClass12():
class myMultiMeta(getClass1(),getClass2()):
pass
return myMultiMeta
class SuperClass12(SuperClass1,SuperClass2):
#class SuperClass12(): gives no errors in class construction but then
#fun1() and fun2() are not members of SuperClass12.
__metaclass__ = getClass12()
class MyClass12(SuperClass12):
Attr = "MC12"
Instance = MyClass12()
Instance.fun1()
Instance.fun2()
sadly I've got this error:
TypeError: Error when calling the metaclass bases metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
but I cannot understand why, since the metaclass myMultiMeta
of my derived class SuperClass12
indeed is a subclass of bothe the metaclasses (MyMetaClass1,MyMetaClass2)
of all its bases (SuperClass1,SUperClass2)
.