[Python-checkins] python/dist/src/Objects listobject.c,2.134,2.135

Guido van Rossum guido@python.org
Thu, 05 Sep 2002 11:30:52 -0400


> I think they added the three-way if tests to handle cases where
> an object instance defined a rich comparison operator and
> returned something other than -1, 0, or 1.  At one time, I
> think 2 and/or -2 had a meaning.  But then, I could be confusing
> it with another story.

In the past, the 3way comparison was unclear about this.  Then a
convention was added that when it sets an exception, a negative number
should be returned; then this was tightened (in most places?) to
require -1 for exceptions.

Then I wrote some code that uses additional conventions for new APIs:
-2 for errors, +2 for NotImplemented.  I am hoping that at some point
in the future we can add this convention to the tp_compare slot
functions, but it's not there yet.  We'll have to go through a period
where these are only supposed to return -2, -1, 0 or 1, and only -2
and -1 are allowed for errors; then encourage -2 for errors; finally
allow +2 for NotImplemented.

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