When do I get "multiple bases have instance lay-out conflict" error?

Miles semanticist at gmail.com
Tue Sep 16 02:30:56 EDT 2008


On Mon, Sep 15, 2008 at 6:06 AM, Harish K Vishwanath
<harish.shastry at gmail.com> wrote:
> Hello all,
>
> When do we actually see the error :
>
> TypeError: Error when calling the metaclass bases
>     multiple bases have instance lay-out conflict
>
>
> I searched the web and I could not find a correct guideline as to when such
> an error could arise. One of the places said that "A new style class cannot
> inherit from more than one python built-in class". That is.,
>
>>>> class A(dict,list):
> ...     pass
> wouldn't work.

"built-in type" generally means "implemented in C", also sometimes
called "extension type".

>>>> class A(Exception,persistent.Persistent):
> ...     pass
> ...
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: Error when calling the metaclass bases
>     multiple bases have instance lay-out conflict
>
> Still declaration of class A fails. Any idea? What is the exact rule when
> python throws up "    multiple bases have instance lay-out conflict" error?

Both the Exception and ZODB Persistent objects are implemented in C,
and they have different ideas for the format of the struct that holds
an object's data.  It can be tricky to tell by introspection whether a
new-style class is implemented in Python or C.  One possible
heuristic:

>>> class Foo(object): pass
...
>>> '__module__' in vars(Foo)
True
>>> '__module__' in vars(Exception)
False

I'm not sure whether this is valid in all cases.  Someone else may
know of a better way.

-Miles



More information about the Python-list mailing list