[Python-Dev] __eq__ vs hash

Daniel Krech eikeon at eikeon.com
Sat Apr 5 18:48:21 CEST 2008

On Apr 4, 2008, at 10:38 AM, Guido van Rossum wrote:
> On Fri, Apr 4, 2008 at 2:46 AM, Ralf Schmitt <schmir at gmail.com> wrote:
>> the news file for python 2.6 does not mention that you need to define
>> __hash__ in case you define __eq__ for a class.
>> This breaks some code (for me: mercurial and pyparsing).
>> Shouldn't this be documented somewhere (I also cannot find it in the
>> whatsnew file).
> Well, technically this has always been the requirement.
> What specific code breaks? Maybe we need to turn this into a warning
> in order to be more backwards compatible?

I think a warning would be nice. I've run into a number of places that  
are breaking due to the change. Including parts of the standard lib,  
in particular, unittest.TestSuite as used by nose [1].

There is already an open issue with patches for this in the issue  
tracker [2]. I've been running trunk with the patch installed and am  
able to get past the breakage due to the change. I don't believe the  
current patch is kicking out a warning however.

[1] http://code.google.com/p/python-nose/issues/detail?id=161
[2] http://bugs.python.org/issue2235

More information about the Python-Dev mailing list