]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
SF bug #800796: Difference between hash() and __hash__()
authorRaymond Hettinger <python@rcn.com>
Fri, 5 Sep 2003 14:38:30 +0000 (14:38 +0000)
committerRaymond Hettinger <python@rcn.com>
Fri, 5 Sep 2003 14:38:30 +0000 (14:38 +0000)
slice(5).__hash__() now raises a TypeError.

Misc/NEWS
Objects/sliceobject.c

index 8181baf4b140c58f0d04e7105d4ca097b069e6b2..9a9e0f8ff3f0db69dec19cebac11e7d5d80dea47 100644 (file)
--- 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
index 796df2bb0cb77a8f17a2db3218ca4d84493418bf..c37af2b027cbd764dc963df623fb57c0b6baf2e2 100644 (file)
@@ -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 */