[Python-Dev] Re: [Python-checkins] CVS: python/dist/src/Objects tupleobject.c,2.48,2.49

Guido van Rossum guido@digicool.com
Tue, 15 May 2001 16:36:57 -0500


Tim wrote:
> BUG ALERT:  The tuple (and list) richcmp algorithm is arguably wrong,
> because it won't believe there's any difference unless Py_EQ returns false
> for some corresponding elements:
> 
> >>> class C:
> ...     def __lt__(x, y): return 1
> ...     __eq__ = __lt__
> ...
> >>> C() < C()
> 1
> >>> (C(),) < (C(),)
> 0
> >>>
> 
> That doesn't make sense -- provided you believe the defn. of C makes sense.

I think in this example the problem is with C, not with the tuple
algorithm.  The question is, what are you going to do otherwise?  You
could test for < first, == second -- but that means twice as many
comparisons, and for reasonably-behaved items it makes no difference
at all.

--Guido van Rossum (home page: http://www.python.org/~guido/)