Multiple inheritance and __slots__
Simon Brunning
simon at brunningonline.net
Thu Dec 14 08:35:58 EST 2006
On 14 Dec 2006 05:23:33 -0800, jm.suresh at no.spam.gmail.com
<jm.suresh at gmail.com> wrote:
> Hi all,
> >From the google search, it seems its not possible to do the following.
>
> >>> class Test1(object):
> ... __slots__ = ['a']
> ...
> >>> class Test2(object):
> ... __slots__ = ['b']
> ...
> >>> class Test3(Test1,Test2):
> ... __slots__ = ['c']
> ...
> 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
>
> I just want to make sure that I am using only the attributes a,b and c
> from the instances of Test3 . Is there any other hack that could be
> done.
Difficulty with subclassing is the price you pay for abusing slots.
Slots are intended as a performance tweak only, to minimise the memory
footprint of classes of which you are going to have a great number of
instances.
In short - don't do that.
--
Cheers,
Simon B
simon at brunningonline.net
http://www.brunningonline.net/simon/blog/
More information about the Python-list
mailing list