[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:

And mainly the overrides_hash call in inherit_slots.

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

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>

More information about the New-bugs-announce mailing list