Skip to content

Commit ed017f0

Browse files
committed
Add a test case.
1 parent b1013fe commit ed017f0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Lib/test/test_hash.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,17 @@ def test_hashes(self):
166166
for obj in self.hashes_to_check:
167167
self.assertEqual(hash(obj), _default_hash(obj))
168168

169+
def test_invalid_hash_typeerror(self):
170+
# GH-140406: The returned object from __hash__() would leak if it
171+
# wasn't an integer.
172+
class A:
173+
def __hash__(self):
174+
return 1.0
175+
176+
for _ in range(100):
177+
with self.assertRaises(TypeError):
178+
hash(A())
179+
169180
class HashRandomizationTests:
170181

171182
# Each subclass should define a field "repr_", containing the repr() of

0 commit comments

Comments
 (0)