Multiple Inheritance __slots__ problem

N

Nitin Shukla

Hello,

Can anyone tell why am I getting this error and how to work around this
problem.
.... __slots__ = ( 'x' )
........ __slots__ = ( 'y' )
........ __slots__ = ( 'z' )
....
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: multiple bases have instance lay-out conflict

I need to define slots in these classes and also need to inherit them in
Derived class.

Nitin
 
A

Alex Martelli

Nitin Shukla said:
Hello,

Can anyone tell why am I getting this error and how to work around this
problem.

... __slots__ = ( 'x' )
...
... __slots__ = ( 'y' )
...
... __slots__ = ( 'z' )
...
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: multiple bases have instance lay-out conflict

You're getting this error because there is no way to merge the layout of
those slots.
I need to define slots in these classes and also need to inherit them in
Derived class.

You never NEED to define slots anywhere: it's just a memory
optimization, that's all there is to it -- you're saving the size of a
dict per instance, a few tens of bytes per instance. Just remove the
slots all around: how many millions of instances of these classes do you
have alive at the same time? Identify the leaf class which has the many
millions of instances and reinstate slots there, only, if you really
truly can't spare the RAM.


Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top