[Python-Dev] getting rid of default object.hash (SF 660098) (original) (raw)

Phillip J. Eby pje at telecommunity.com
Mon Dec 22 16:19:10 EST 2003


At 01:04 PM 12/22/03 -0800, Guido van Rossum wrote:

New-style classes inherit a default hash from object, but this is incorrect if the inheriting object defines eq or cmp.

This has been reported several times; the roll-up SF entry is 660098, which has the proposed patch attached as newpatch.txt. I've long pondered this, and it seems the best solution is to simply not define hash on the base object class. After all, you don't inherit eq or cmp either; the default comparison behavior is supplied by intrinsic behavior of comparisons, and the default hash() behavior is also supplied by intrinsic behavior of hash(). Does anybody have any reason why I shouldn't check in this change in 2.4? There's no unit test that fails if I do this.

Would this mean that instances of the following class:

class Dummy(object): pass

would no longer be usable as dictionary keys? I guess the parts I'm not clear on are 1) whether dictionaries call the equivalent of 'hash(key)' or 'key.hash()', and 2) whether 'hash(Dummy())' will do something meaningful.



More information about the Python-Dev mailing list