keying by identity in dict and set
Peter Otten
__peter__ at web.de
Sun Oct 20 13:54:26 EDT 2019
Steve White wrote:
> Hi Peter,
>
> Yes you are right. In fact, I shouldn't even have mentioned the
> hash() function... it came from a line of reasoning about what an
> implementation might do if very large integers were returned by
> __hash__(), and some remarks about the value returned by id() applied
> to small integers.
>
> The point is, I don't think __eq__() is ever called in a situation as
> described in my post, yet the Python documentation states that if
> instances are to be used as keys, it must not be used to determine if
> non-identical instances are equivalent.
What else should be used if not __eq__()? Where in the docs did you you see
such a statement?
The only limitation for a working dict or set is that for its keys or
elements
(1) a == b implies hash(a) == hash(b)
(2) a == a
Does your custom class violate one of the above?
More information about the Python-list
mailing list