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

Neal Norwitz neal@metaslash.com
Thu, 05 Sep 2002 15:41:44 -0400


Guido van Rossum wrote:
> 
> > 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.

Would it be best for sq_contains to only return -1, 0, and 1 or 
return the same values as PyObject_RichCompare()?

Also the same optimization made to list_contains() can be
made for tuplecontains().

Neal