[Python-bugs-list] [ python-Bugs-427698 ] objects with __eq__ are not hashable

noreply@sourceforge.net noreply@sourceforge.net
Sun, 27 May 2001 05:36:00 -0700


Bugs item #427698, was updated on 2001-05-27 05:35
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=427698&group_id=5470

Category: Python Interpreter Core
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: objects with __eq__ are not hashable

Initial Comment:
The following code fails with Python2.1, on both SGI
IRIX 6.5 and Linux (Suse7.1)

class A:
    _name = 'AA'
    def __init__(self,name):
        self._name = name
    def __eq__(self,a):
        if (a._name == self._name):
            return 1
        else:
            return 0
    def __str__(self):
        return self._name

a = A('abc')

c = {}

c[a] = 1


===> 
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: unhashable instance

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

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