return self
self.assertEqual(hash(Z(42)), hash(42))
+ def test_invalid_hash_typeerror(self):
+ # GH-140406: The returned object from __hash__() would leak if it
+ # wasn't an integer.
+ class A:
+ def __hash__(self):
+ return 1.0
+
+ with self.assertRaises(TypeError):
+ hash(A())
+
def test_hex(self):
self.assertEqual(hex(16), '0x10')
self.assertEqual(hex(-16), '-0x10')
return PyObject_HashNotImplemented(self);
}
if (!PyLong_Check(res)) {
+ Py_DECREF(res);
PyErr_SetString(PyExc_TypeError,
"__hash__ method should return an integer");
return -1;