Don't use __slots__ (was Re: Problem of Readability of Python)

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Mon Oct 8 08:38:52 EDT 2007


On Sun, 07 Oct 2007 21:27:31 -0700, Aahz wrote:

> In article <2tqdncU0D6K8v5TanZ2dnUVZ_hGdnZ2d at comcast.com>, Steven
> Bethard  <steven.bethard at gmail.com> wrote:
>>
>>You can use __slots__  [...]
> 
> Aaaugh!  Don't use __slots__!
> 
> Seriously, __slots__ are for wizards writing applications with huuuge
> numbers of object instances (like, millions of instances).  For an
> extended thread about this, see
> 
> http://groups.google.com/group/comp.lang.python/browse_thread/
thread/8775c70565fb4a65/0e25f368e23ab058

Well, I've read the thread, and I've read the thread it links to, and for 
the life of me I'm still no clearer as to why __slots__ shouldn't be used 
except that:

1 Aahz and Guido say __slots__ are teh suxxor;

2 rumour (?) has it that __slots__ won't make it into Python 3.0;

3 inheritance from classes using __slots__ doesn't inherit the slot-
nature of the superclass.


Point 1 is never to be lightly dismissed, but on the other hand Guido 
doesn't like reduce(), and I'm allergic to "Cos I Said So" arguments.

History is full of things which were invented for one purpose being used 
for something else. So, that being the case, suppose I accept that using 
__slots__ is not the best way of solving the problem, and that people of 
the skill and experience of Guido and Aahz will roll their eyes and 
snicker at me.

But is there actually anything *harmful* that can happen if I use 
__slots__?



-- 
Steven.



More information about the Python-list mailing list