mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
Set __hash__ to None for types that defines __eq__, but not __hash__ (#2291)
fixes #2191
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user