del c
vereq(log, [1])
+def hashinherit():
+ if verbose: print "Testing hash of mutable subclasses..."
+
+ class mydict(dict):
+ pass
+ d = mydict()
+ try:
+ hash(d)
+ except TypeError:
+ pass
+ else:
+ raise TestFailed, "hash() of dict subclass should fail"
+
+ class mylist(list):
+ pass
+ d = mylist()
+ try:
+ hash(d)
+ except TypeError:
+ pass
+ else:
+ raise TestFailed, "hash() of list subclass should fail"
+
def test_main():
class_docstrings()
lists()
str_of_str_subclass()
kwdargs()
delhook()
+ hashinherit()
if verbose: print "All OK"
if __name__ == "__main__":
return result;
}
+static long
+dict_nohash(PyObject *self)
+{
+ PyErr_SetString(PyExc_TypeError, "dict objects are unhashable");
+ return -1;
+}
+
static PyObject *
dict_iter(dictobject *dict)
{
0, /* tp_as_number */
&dict_as_sequence, /* tp_as_sequence */
&dict_as_mapping, /* tp_as_mapping */
- 0, /* tp_hash */
+ dict_nohash, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */
return 0;
}
+static long
+list_nohash(PyObject *self)
+{
+ PyErr_SetString(PyExc_TypeError, "list objects are unhashable");
+ return -1;
+}
+
static char append_doc[] =
"L.append(object) -- append object to end";
static char extend_doc[] =
0, /* tp_as_number */
&list_as_sequence, /* tp_as_sequence */
0, /* tp_as_mapping */
- 0, /* tp_hash */
+ list_nohash, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_as_number */
&immutable_list_as_sequence, /* tp_as_sequence */
0, /* tp_as_mapping */
- 0, /* tp_hash */
+ list_nohash, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */