Set __hash__ to None for types that defines __eq__, but not __hash__ (#2291)

fixes #2191
This commit is contained in:
Sergei Izmailov
2020-07-27 02:44:25 +03:00
committed by GitHub
parent aab701399a
commit 7b067cc387
3 changed files with 56 additions and 1 deletions

View File

@@ -127,3 +127,19 @@ def test_nested():
assert abase.value == 42
del abase, b
pytest.gc_collect()
def test_overriding_eq_reset_hash():
assert m.Comparable(15) is not m.Comparable(15)
assert m.Comparable(15) == m.Comparable(15)
with pytest.raises(TypeError):
hash(m.Comparable(15)) # TypeError: unhashable type: 'm.Comparable'
for hashable in (m.Hashable, m.Hashable2):
assert hashable(15) is not hashable(15)
assert hashable(15) == hashable(15)
assert hash(hashable(15)) == 15
assert hash(hashable(15)) == hash(hashable(15))