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

Documentation of __hash__

Stefan Halfpap wrote at 2020-2-5 14:57 +0100:
>I do not understand the following statement from the python (2 and 3) documentation regarding __hash__ and __eq__ methods:
>"If a class does not define an __eq__() <> method it should not define a __hash__() <> operation either;?
>(see <> )
>I thought it relates to the second part (?if it defines __eq__() <> but not __hash__() <>, its instances will not be usable as items in hashable collections?), which is totally clear to me.
>But then the implication should be the other way around.

"if not A then not B" is equivalent to "if B then A".

In your case: "__eq__ not defined, then __hash__ not defined"
is equivalent to "__hash__ definied requires __eq__ defined".