Christian Heimes <> writes:
> Also this code is going to use much more memory than an ordinary tuple
> since every instance of InternedTuple has a __dict__ attribute. This
> code works but I had to move the cache outside the class because of
> __slots__.
Wouldn't it work inside the class as well? __slots__ applies to
instances, not to classes themselves. In Python 3.1:
>>> class Foo(tuple):
.... __slots__ = ()
.... _cache = {}
....
>>> Foo._cache # works as expected
{}
>>> Foo()._cache # and so does this
{}
|