[Python-3000] bytes and dicts (was: PEP 3137: Immutable Bytesand Mutable Buffer)
Phillip J. Eby
pje at telecommunity.com
Sat Sep 29 16:24:02 CEST 2007
At 08:08 PM 9/28/2007 -0700, Guido van Rossum wrote:
>Likely, programmers will attempt to look up keys
>that they know are in the dict -- and if they use the wrong type,
>because of the identical hash values, they will get the TypeError as
>soon as they compare it to the first object at the hashed location.
I'm coming into this thread a little bit late, but if we don't want
strings and bytes to be comparable, shouldn't we just make them
*unequal*? I mean, under normal circumstances, == and != are
available on all objects without causing errors, and the same
TypeError would occur for things like list.remove().
This seems a lot like Oleg's question on Python-Dev the other day,
about raising a TypeError from __nonzero__: i.e., changing a
significant expectation about all "normal" objects.
While it's true that it would be good to know when you've
unintentionally mixed bytes and strings, surely there could be less
fatal ways to find this, like perhaps a command-line option that
causes byte/string comparisons to output a warning?
More information about the Python-3000