[Python-Dev] Re: Alternative implementation of string interning

Oren Tirosh oren-py-d@hishome.net
Wed, 3 Jul 2002 05:59:15 -0400


On Wed, Jul 03, 2002 at 02:33:24AM -0700, Ka-Ping Yee wrote:
> I just went on what you wrote: "No two istr instances are equal unless
> they are identical."  I read that to mean that == would be implemented
> with pointer comparison, which would break contracts the way i described.
> I see now that is not what you meant.

If all dutchmen like Monty Python it doesn't mean that anyone who likes
Monty Python is a dutchman.

> It appears that what you are proposing is what interned string
> comparison already does (since == checks for pointer equality first).

But INequality checking may still require strcmp.  Inverse logic again.

> So, the only observable effect of the change would be to break all
> code that tests for type(s) == str.

Yes, that's certainly a problem.  

This thought experiment is part of a strange fantasy I have that Python 
might one day use only interned strings to represent names. There are 
relatively few places where a string may be converted to a name (getattr, 
hasattr, etc) and these could be interned at the interface if interned 
strings are not immortal. I expect that nothing will ever come out of this, 
but it's fun to think about it anyway...

	Oren