[Python-Dev] Python 3.x and bytes

"Martin v. Löwis" martin at v.loewis.de
Wed May 18 23:58:21 CEST 2011


>> Immutable objects that compare equal should hash equal;
>> so we would also have to change the hashing of byte strings. Not sure
>> whether that, in turn, has undesirable consequences.
> 
> I thought it was the other-way-round -- if they hash equal, they should
> compare equal?

No no no. If they hash equal, it could just be a hash collision -
objects of a class could all hash to 42, if they wanted to.
Dictionaries require the property I mentioned. If they compare
equal, but hash differently, a dictionary lookup would fail to
find the key.

>> In addition, equality should be transitive, so b'A' == 65.0.
> 
> I'm not sure what you're getting at...

That it is counter-intuitive to have a bytes object compare equal
to a floating-point number.

Regards,
Martin


More information about the Python-Dev mailing list