New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New-style classes with __eq__ but not __hash__ are hashable #39631
Comments
According to the current reference docs, "If [a class] Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build
1495)] on darwin
Type "help", "copyright", "credits" or "license" for
more information.
>>> class A(object):
... def __cmp__(self, other): return -1
>>> print {A():1}
{<__main__.A object at 0x71cf0>: 1} The problem is that object defines a default __hash__ >>> print A.__hash__
<slot wrapper '__hash__' of 'object' objects> So the dictionary class thinks that the object is >>> class A(object):
... def __cmp__(self, other): return -1
... def __hash__(self):
... raise TypeError, ('%s objects are unhashable'
%
... self.__class__) But it seems like this should be fixed in Python itself. I
So.. Is this a real bug, or am I missing something? And -Edward [1] http://www.python.org/doc/current/ref/ |
Logged In: YES It has been a subject of debate but the behavior is already The preferred way to make things unhashable is: def __hash__(self)
return NotImplemented |
Logged In: YES Can you point me to the debate? I searched the python & Using "return NotImplemented" does *not* seem like the If this behavior is indeed set in stone, then this should be -Edward |
Logged In: YES I should have been clearer. The bug has been discussed several times before (SF 475877, I rechecked my notes, the right way to implement such a |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: