A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2000-July/007430.html below:

[Python-Dev] decoding errors when comparing strings

[Python-Dev] decoding errors when comparing strings [Python-Dev] decoding errors when comparing stringsGuido van Rossum guido@beopen.com
Wed, 26 Jul 2000 07:57:02 -0500
> > I see the exception as a useful warning that the program isn't
> > sufficiently Unicode aware to work correctly.  That's a *good* thing
> > in my book -- I'd rather raise an exception than silently fail.
> 
> I assume that means you're voting for alternative 3:
> 
>     "a third alternative would be to keep the exception, and make
>     the dictionary code exception proof."

Yes.

> because the following isn't exactly good behaviour:
> 
> >>> a = "„"
> >>> b = unicode(a, "iso-8859-1")
> >>> d = {}
> >>> d[a] = "a"
> >>> d[b] = "b"
> >>> len(d)
> UnicodeError: ASCII decoding error: ordinal not in range(128)
> >>> len(d)
> 2
> 
> (in other words, the dictionary implementation misbehaves if items
> with the same hash value cannot be successfully compared)

Good point.  This would happen if you used flakey class instances as
keys as well!

(Note that the exception really happens on the d[b] = "b" statement;
but because the dict implementation doesn't check for exceptions, it
gets reported too late.  We've seen this kind of bugs before in
Python.)

--Guido van Rossum (home page: http://www.pythonlabs.com/~guido/)



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4