hash(unicode(string)) == hash(string) sometimes (was Re: Why KeyError ???)

Martin v. Loewis martin at v.loewis.de
Thu Mar 7 02:59:38 EST 2002


sjmachin at lexicon.net (John Machin) writes:

> If the "fix" for this would involve making hash(string) always do
> hash(unicode(string)) then I sure hope that (borrowing timbot
> phraseology) somebody optimises the snot out of it.

The real solution, IMO, is to never change the system default
encoding. Then auto-conversion will only apply to ASCII strings,
and dictionary lookup will either succeed properly, or fail with
a UnicodeError - which will indicate a bug in the program, as it
would need to explicitly apply a non-default encoding.

Regards,
Martin




More information about the Python-list mailing list