[Python-Dev] decoding errors when comparing strings
M.-A. Lemburg
mal@lemburg.com
Sat, 15 Jul 2000 19:59:56 +0200
"M.-A. Lemburg" wrote:
>
> BTW, I have a feeling that we should mask the decoding errors
> during compares in favour of returning 0...
>
> ...otherwise the current dictionary would bomb (it doesn't do any
> compare error checking !) in case a Unicode string happens to have
> the same hash value as an 8-bit string key. (Can't test this right now,
> but this is what should happen according to the C sources.)
Here's the test:
>>> s = 'ä'
>>> u = u'ä'
>>> hash(s)
-880683291
>>> hash(u)
-880683291
>>> d = {s:1}
>>> d[s]
1
>>> d[u]
Traceback (most recent call last):
File "<stdin>", line 1, in ?
KeyError>>>
>>>
Looks strange, doesn't it...
--
Marc-Andre Lemburg
______________________________________________________________________
Business: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/