[Python-ideas] incremental hashing in __hash__

Ethan Furman ethan at stoneleaf.us
Fri Dec 30 20:04:58 EST 2016


On 12/30/2016 04:31 PM, jab at math.brown.edu wrote:
> On Fri, Dec 30, 2016 at 7:20 PM, Ethan Furman wrote:

>> If you are relying on an identity check for equality then no two
>>  FrozenOrderedCollection instances can be equal.  Was that your
>>  intention?  It it was, then just hash the instance's id() and
>>  you're done.
>
> No, I was talking about the identity check done by a set or dict
>  when doing a lookup to check if the object in a hash bucket is
>  identical to the object being looked up. In that case, there is
>  no need for the set or dict to even call __eq__.  Right?

No.  It is possible to have two keys be equal but different -- an easy example is 1 and 1.0; they both hash the same, equal the same, but are not identical.  dict has to check equality when two different objects hash the same but have non-matching identities.

--
~Ethan~


More information about the Python-ideas mailing list