[Python-bugs-list] [ python-Bugs-800796 ] Difference between hash() and __hash__()

SourceForge.net noreply at sourceforge.net
Thu Sep 4 17:52:49 EDT 2003


Bugs item #800796, was opened at 2003-09-04 23:46
Message generated for change (Comment added) made by fleiter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=800796&group_id=5470

Category: None
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Stefan Fleiter (fleiter)
Assigned to: Raymond Hettinger (rhettinger)
Summary: Difference between hash() and __hash__()

Initial Comment:


Raymond told me in comp.lang.python to submit

this bug, he is working on a fix.



>>> s = slice(None,5)

>>> s.__hash__()

136748064

>>> hash(s)

Traceback (most recent call last):

  File "<stdin>", line 1, in ?

TypeError: unhashable type



----------------------------------------------------------------------

>Comment By: Stefan Fleiter (fleiter)
Date: 2003-09-04 23:52

Message:
Logged In: YES 
user_id=502578



Terry J. Reedy commented in comp.lang.python:

-------------------------------------------------------------------------

Ref Manual 5.3.3 Slicings says nothing about hashability. 

If not

hashable, in spite of being mutable, "Slices are not

hashable" could

be added at end.



Ref Manual 3.3.1 Basic customization, __hash__( self) entry says

"Called for the key object for dictionary operations, and by the

built-in function hash() "



This implies to me that if there is a __hash__() method,

then hash()

will call it.  If not true, then a 'maybe' could be added.



Lif Maual 2.1 Built-in Functions, hash( object) says only

"Return the hash value of the object (if it has one)."

If having __hash__() does not mean 'has one', then what does.



----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=800796&group_id=5470



More information about the Python-bugs-list mailing list