[Python-3000] bytes and dicts (was: PEP 3137: Immutable Bytes and Mutable Buffer)

Jim Jewett jimjjewett at gmail.com
Fri Sep 28 21:02:59 CEST 2007


On 9/28/07, Guido van Rossum <guido at python.org> wrote:

> The question is whether it's worth the effort to raise TypeError when
> the *potential* exists that a certain hash sequence *could* raise this
> TypeError.

Bugs depending on the hash sequence are exactly the sort of thing that
doesn't get found by tests, and can't be easily reproduced.

> I'm less and less convinced -- after all, we're making the
> exception only for bytes/str, not for other types that might raise
> TypeError upon comparison.

What would those other types be?

As you point out in the "Bytes and the Str Type" section, this
exception violates the "general rule that comparing objects of
different types for equality
should just return False".

In Py3, there are plenty of types that aren't orderable, but I still
can't think of any[*] others that raise an exception when tested just
for equality.

[*]  It is of course possible to write a malicious class, and it is
possible to write a buggy class.  Even then, most buggy classes fail
when compared to anything from any other class, rather than just for
specific banned comparisons.

-jJ


More information about the Python-3000 mailing list