[docs] [issue30026] Hashable doesn't check for __eq__

Max report at bugs.python.org
Sun Apr 9 12:23:03 EDT 2017


New submission from Max:

I think collections.abc.Hashable.__subclasshook__ should check __eq__ method in addition to __hash__ method. This helps detect classes that are unhashable due to:

to __eq__ = None

Of course, it still cannot detect:

def __eq__: return NotImplemented

but it's better than nothing.

In addition, it's probably worth documenting that explicitly inheriting from Hashable has (correct but unexpected) effect of *suppressing* hashability that was already present:

from collections.abc import Hashable
class X: pass
assert issubclass(X, Hashable)
x = X()

class X(Hashable): pass
assert issubclass(X, Hashable)
x = X() # Can't instantiate abstract class X with abstract methods

----------
assignee: docs at python
components: Documentation, Interpreter Core
messages: 291382
nosy: docs at python, max
priority: normal
severity: normal
status: open
title: Hashable doesn't check for __eq__

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30026>
_______________________________________


More information about the docs mailing list