From 046595e496678e65e88905f64072256c4b716f2f Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 5 Sep 2003 14:38:30 +0000 Subject: [PATCH] SF bug #800796: Difference between hash() and __hash__() slice(5).__hash__() now raises a TypeError. --- Misc/NEWS | 2 ++ Objects/sliceobject.c | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) 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 */ -- 2.47.3