osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Documentation of __hash__


On 2/6/20 2:13 PM, klauck2 at gmail.com wrote:
> The default __eq__ method (object identity) is compatible with all (reasonable) self-defined __hash__ method.
>
> Stefan

If __eq__ compares just the id, then the only hash you need is the 
default that is also the id. If you define a separate hash function, 
which uses some of the 'value' of the object, then presumably you intend 
for objects where that 'value' matches to be equal, which won't happen 
with the default __eq__.

-- 
Richard Damon