Don't use __slots__ (was Re: performance of dictionary lookup vs. object attributes)

skip at pobox.com skip at pobox.com
Sat Aug 26 16:28:54 EDT 2006


    Aahz> Taking a look at __slots__ is fine as long as you don't actually
    Aahz> use them.

    Gabriel> Why?

    Skip> http://groups.google.com/group/comp.lang.python/browse_thread/thread/451ad25f9c648404/f4ac2dfde32b16fd?lnk=st&q=Python+__slots__+aahz&rnum=2#f4ac2dfde32b16fd

    Patrick> The subject of __slots__ really seems to get some people's
    Patrick> dander up, to the extent where the heat/light ratio in the
    Patrick> discussion becomes uncomfortably high.  Right here, we have
    Patrick> Skip referring to a post by Aahz, where Aahz says that Guido
    Patrick> says that slots are bad mojo, without anybody ever giving
    Patrick> concrete examples about why this may be the case.  The only
    Patrick> assertion that was made explicitly enough to be testable came
    Patrick> about in a followup to Aahz's original post, only AFTER someone
    Patrick> asked what the side-effects associated with __slots__ were.
    Patrick> Aahz responded:

No dander on my part.  I was just pointing out an earlier thread on the
topic.  Note however that the ultimate source of the anti-slots fervor in
that thread is Guido himself (may he live long and prosper as BDFL).  If
Guido thinks it's bad mojo, that's good enough for me.  Also, if he thinks
it's bad mojo now, my suspicion is that you won't see it in Py3k.

That said,  It's not mentioned on the Python3.0 page of the wiki:

    http://wiki.python.org/moin/Python3.0

or in PEP 3000:

    http://www.python.org/dev/peps/pep-3000/

and I see no discussion about it in the Python 3000 mailing list archives:

    http://mail.python.org/pipermail/python-3000/

though Ian Bicking asks about it here:

    http://wiki.python.org/moin/Python3%2e0Suggestions#head-fc89a0fe3f697418776925f4828ea863031fbbd2

Skip



More information about the Python-list mailing list