Hi, i have two questions converning metaclasses and multiple inheritance. The first is: Why do i get a TypeError for the class Derived
but not for Derived2
?
class Metaclass(type): pass
class Klass(object):
__metaclass__ = Metaclass
#class Derived(object, Klass): pass # if I uncomment this, I get a TypeError
class OtherClass(object): pass
class Derived2(OtherClass, Klass): pass # I do not get a TypeError for this
The exact error message is:
TypeError: Error when calling the metaclass bases Cannot create a consistent method resolution order (MRO) for bases object, Klass
The second question is: Why does super
not work in this case(if I use __init__
instead of __new__
, super
works again):
class Metaclass(type):
def __new__(self, name, bases, dict_):
return super(Metaclass, self).__new__(name, bases, dict_)
class Klass(object):
__metaclass__ = Metaclass
There I get:
TypeError: Error when calling the metaclass bases type.new(X): X is not a type object (str)
I'm using Python 2.6.