[Python-Dev] Dicts are broken Was: unicode hell/mixing str and unicode asdictionarykeys
Michael Hudson
mwh at python.net
Fri Aug 4 16:38:32 CEST 2006
Michael Chermside <mcherm at mcherm.com> writes:
> I'm changing the subject line because I want to convince everyone that
> the problem being discussed in the "unicode hell" thread has nothing
> to do with unicode and strings. It's all about dicts.
I'd say it's more to do with __eq__. It's a strange __eq__ method
that raises an Exception, IMHO.
Please do realize that the motivation for this change was hours and
hours of tortous debugging caused by a buggy __eq__ method making keys
"impossibly" seem to not be in dictionaries.
> I have not observed real breakage in my own code, but I will present
> a sample of made-up-but-completely-reasonable code that works in
> 2.4, fails in 2.5, and arguably ought to work fine. I think we should
> restore the behavior of dicts that when they compare keys for
> equality they suppress exceptions (treating the objects as unequal),
> or at LEAST retain the behavior for one more release making it a
> warning this time.
Please no. Here's just one piece of evidence that the 2.4 semantics
are pretty silly too:
>>> d = {u'\xe0':1, '\xe0\:2}
File "<stdin>", line 1
d = {u'\xe0':1, '\xe0\:2}
^
SyntaxError: EOL while scanning single-quoted string
>>> d = {u'\xe0':1, '\xe0':2}
>>> '\xe0' in d
True
>>> '\xe0' in d.keys()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)
Cheers,
mwh
--
same software, different verbosity settings (this one goes to
eleven) -- the effbot on the martellibot
More information about the Python-Dev
mailing list