Python Metaclass Bases lay-out Conflicts issue

Posted by svram on 2016-06-15 06:43

All,

I am facing some issues in Python Metaclasses when I am trying to do Multiple inheritance.

from traits.api import HasTraits

class Sample1(AnotherClass, HasTraits):
    pass

For the above code, it was throwing

metaclass conflict: the metaclass of a derived class must be a (non-strict)

Then I changed the code like this

from traits.api import HasTraits

class Sample1_Meta(type(HasTraits), type(AnotherClass)):
    pass

class Sample1(AnotherClass, HasTraits):
    __metaclass__ = Sample1_Meta

For the above code, it was throwing

multiple bases have instance lay-out conflict

I understand that the issue is with respect to the initialization of slots of those two classes being inherited. Questions

1. Can I change the slot of the class dynamically?
2. Is there any other way to resolve this issue?

PS: I am not provided with the definition of AnotherClass definition.

Regards,
Ram