Why in the code below does metaclass with object base raise metaclass conflict exception?
"metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases"
class M_A(object): pass
class A(object, metaclass = M_A): pass
So does another code:
class M_A(list): pass
class A(object, metaclass = M_A): pass
I understand that the cpython will interpret the above code as:
A = M_A.__new__(M_A, 'A', (object,), {})
What confuses me is that the base class of A is object, and any class is subclass of object. This error is so strange. What's wrong with me?
M_A
is not a subclass of a metaclass of any base class ofA
.class M_A(type): pass
will probably work. - vaultahM_A(list)
is a subclass ofobject
, yes. But that's not what the error message is about.M_A
has to be a subclass ofobject
's metaclass, which istype
. - Aran-Fey