[issue2235] __eq__ / __hash__ check doesn't take inheritance into account
Guido van Rossum
report at bugs.python.org
Thu Apr 10 18:46:57 CEST 2008
Guido van Rossum <guido at python.org> added the comment:
Hi Amaury, thanks for your work on this. I applied your patch and looked
at the code but there seem to be some issues left still.
(1) I don't think you need to add a warning to classic classes that
define __eq__ without __hash__ -- these aren't hashable and never were.
The problem is purely with new classes AFAICT.
(2) I can't seen to trigger the warning for new classes (and yes, I
specified -3 on the command line :-):
>>> class C(object):
... def __eq__(self, other): return False
...
>>> hash(C())
-134976284
(3) test_Hashable in test_collections.py fails. This is because the
Hashable class believes that list, set, and dict are hashable.
Something odd is going on:
>>> list.__hash__([])
-135100116
but
>>> hash([])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
Note that in 2.5, both raise TypeError.
----------
assignee: -> amaury.forgeotdarc
__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2235>
__________________________________
More information about the Python-bugs-list
mailing list