[New-bugs-announce] [issue1549] Regression with __hash__ definition and rich comparison operators

Thomas Herve report at bugs.python.org
Mon Dec 3 14:51:31 CET 2007


New submission from Thomas Herve:

A new behavior was introduced in r59106 in python trunk, which look
suspicious to me. Basically, every time a class defines a comparison
operator, it's __hash__ method is defined to None. The simple following
example shows it:

>>> class A(object):
...     def __init__(self, b):
...             self.b = b
...     def __cmp__(self, other):
...             if not isinstance(other, A):
...                     return -1
...             return cmp(self.b, other.b)
...
>>> hash(A(2))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable


The problematic change is here:
http://svn.python.org/view/python/trunk/Objects/typeobject.c?rev=59106&r1=58032&r2=59106

And mainly the overrides_hash call in inherit_slots.

FWIW, I've encounter the problem because zope.interface is now usable on
trunk.

----------
components: Interpreter Core
messages: 58124
nosy: therve
severity: major
status: open
title: Regression with __hash__ definition and rich comparison operators
type: crash
versions: Python 2.6

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1549>
__________________________________


More information about the New-bugs-announce mailing list