Issue 2235: __hash__ is once again inherited by default, but inheritance can be blocked explicitly so that collections.Hashable remains meaningful
diff --git a/Objects/object.c b/Objects/object.c
index f40fd9f..9cd34b8 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -1083,6 +1083,13 @@
#endif
}
+long
+PyObject_HashNotImplemented(PyObject *self)
+{
+ PyErr_Format(PyExc_TypeError, "unhashable type: '%.200s'",
+ self->ob_type->tp_name);
+ return -1;
+}
long
PyObject_Hash(PyObject *v)
@@ -1094,9 +1101,7 @@
return _Py_HashPointer(v); /* Use address as hash value */
}
/* If there's a cmp but no hash defined, the object can't be hashed */
- PyErr_Format(PyExc_TypeError, "unhashable type: '%.200s'",
- v->ob_type->tp_name);
- return -1;
+ return PyObject_HashNotImplemented(v);
}
PyObject *