Multiple Inheritance __slots__ problem
craig at postnewspapers.com.au
Sat Dec 25 14:13:00 CET 2004
On Fri, 2004-12-24 at 20:07, Nitin Shukla wrote:
> Can anyone tell why am I getting this error and how to work around this
> >>> class Klass(object):
> ... __slots__ = ( 'x' )
> >>> class Klass1(object):
> ... __slots__ = ( 'y' )
> >>> class Klass(Klass, Klass1):
> ... __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.
If I recall correctly, the standard advice in this situation is "don't
use __slots__. If you think you need __slots__, still don't use
I've made use of __slots__ once myself for an optimisation when
subclassing `str', but if you're not using it for a serious optimisation
need it's probably best to steer clear.
More information about the Python-list