From: Raymond Hettinger Date: Fri, 5 Sep 2003 14:38:30 +0000 (+0000) Subject: SF bug #800796: Difference between hash() and __hash__() X-Git-Tag: v2.3.1~85 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=046595e496678e65e88905f64072256c4b716f2f;p=thirdparty%2FPython%2Fcpython.git SF bug #800796: Difference between hash() and __hash__() slice(5).__hash__() now raises a TypeError. --- diff --git a/Misc/NEWS b/Misc/NEWS index 8181baf4b140..9a9e0f8ff3f0 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,8 @@ What's New in Python 2.3.1? Core and builtins ----------------- +- Bug #800796: slice(1).__hash__() now raises a TypeError, unhashable type. + - Bug #603724: Pass an explicit buffer to setvbuf in PyFile_SetBufSize(). - Bug #795506: The % formatting operator did not support '%F' as diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c index 796df2bb0cb7..c37af2b027cb 100644 --- a/Objects/sliceobject.c +++ b/Objects/sliceobject.c @@ -278,6 +278,13 @@ slice_compare(PySliceObject *v, PySliceObject *w) return result; } +static long +slice_hash(PySliceObject *v) +{ + PyErr_SetString(PyExc_TypeError, "unhashable type"); + return -1L; +} + PyTypeObject PySlice_Type = { PyObject_HEAD_INIT(&PyType_Type) 0, /* Number of items for varobject */ @@ -293,7 +300,7 @@ PyTypeObject PySlice_Type = { 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ - 0, /* tp_hash */ + (hashfunc)slice_hash, /* tp_hash */ 0, /* tp_call */ 0, /* tp_str */ PyObject_GenericGetAttr, /* tp_getattro */