[Python-Dev] eq vs hash (original) (raw)
Jean-Paul Calderone exarkun at divmod.com
Sat Apr 5 01:37:23 CEST 2008
- Previous message: [Python-Dev] __eq__ vs hash
- Next message: [Python-Dev] __eq__ vs hash
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, 4 Apr 2008 07:38:04 -0700, Guido van Rossum <guido at python.org> 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?
There was some code in Twisted (one class, specifically) which was broken/ revealed to be broken by this Python 2.6 change. The code assumed identity hashing if no hash method was implemented. This ended up only working if you only had a singleton instance of the class, but the class also went out of its way to make sure that was the case. We have since changed the code to work on Python 2.6.
If you're curious about the details, here's the code after the fix:
http://twistedmatrix.com/trac/browser/trunk/twisted/web2/dav/element/base.py?rev=22305#L345
Here's the changeset that fixed it:
http://twistedmatrix.com/trac/changeset/22305
And here's the same class before the fix:
http://twistedmatrix.com/trac/browser/trunk/twisted/web2/dav/element/base.py?rev=22304#L344
Jean-Paul
- Previous message: [Python-Dev] __eq__ vs hash
- Next message: [Python-Dev] __eq__ vs hash
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]