difflib + object sequences

Tim Peters tim.one at comcast.net
Tue Mar 23 21:45:58 CET 2004

[Chris Green]
> ...
> I've narrowed this down to difflib.py ( both 2.3 and CVS's ) using a
> dictionary on the backend and hash(Misc(1)) != hash(Misc(1)).
> Is this expected behavior?
> shows some coments on objects inheriting a default __hash__ ret
> self(id).
> If I define __hash__ as return hash(self.val), things work as
> expected.  Now the question is, what should I log as a bug?
> The existing bug 660098?

It's part of the existing bug.  Old-style classes work the way a comment in
that bug report said they worked:

to be usable as a dict key, an instance's class must either:

1. Implement none of {__cmp__, __eq__, __hash__}.


2. Implement __hash__ and (at least) one of {__cmp, __eq__}.

It's a bug (bug 660098, in fact) that new-style classes didn't follow the
same rules.

More information about the Python-list mailing list