[Python-Dev] d.get_key(key) -> key?
Guido van Rossum
Wed, 05 Jun 2002 21:44:26 -0400
> Our objects are subclasses of string.
Ah, those can't be interned.
> >Seems to me that if the implementation of interning were
> >smart enough, it would be able to drop strings that were
> >not referenced from anywhere else.
> >Maybe *that* would be a useful feature to add?
> Yes. Especially if it could be made to work with subclasses of string ;)
Alas, subclasses of str can't be interned. Consider the following
scenario. You intern a str-subclass-instance with value "foo" that
implements a funky __repr__. Some other unrelated piece of code
interns the string "foo". When they apply repr() to it, they'll be
very unhappy that their string has been turned into something else.
(In fact, the interning code, when it sees a str-subclass-instance,
makes a copy as a true str instance.)
--Guido van Rossum (home page: http://www.python.org/~guido/)