[Python-Dev] Re: __slots__ and default values

Raymond Hettinger python@rcn.com
Wed, 14 May 2003 02:51:24 -0400


> It's also a bad idea for initializers that aren't immutable, because
> the initial values are shared between all instances (another example
> of the "aliasing" problem, also known from default argument values).

Right.  I once knew that and had forgotten.


> > Though I think of __slots__ as a way to make lighter weight instances,
> > constraining instance variables is also one of its functions. 
> 
> Not true.  That is at best an unintended side effect of slots.  And
> there's nothing against having __slots__ include __dict__, so your
> instance has a __dict__ as well as slots.

That's something I never knew but wish I had known (and I *have*
read the source).  Live and learn.


Raymond