@@ -500,35 +500,19 @@ PyObject_Bytes(PyObject *v)
500500 return PyBytes_FromObject (v );
501501}
502502
503- /* The new comparison philosophy is: we completely separate three-way
504- comparison from rich comparison. That is, PyObject_Compare() and
505- PyObject_Cmp() *just* use the tp_compare slot. And PyObject_RichCompare()
506- and PyObject_RichCompareBool() *just* use the tp_richcompare slot.
503+ /* For Python 3.0.1 and later, the old three-way comparison has been
504+ completely removed in favour of rich comparisons. PyObject_Compare() and
505+ PyObject_Cmp() are gone, and the builtin cmp function no longer exists.
506+ The old tp_compare slot will be renamed to tp_reserved, and should no
507+ longer be used. Use tp_richcompare instead.
507508
508509 See (*) below for practical amendments.
509510
510- IOW, only cmp() uses tp_compare; the comparison operators (==, !=, <=, <,
511- >=, >) only use tp_richcompare. Note that list.sort() only uses <.
511+ tp_richcompare gets called with a first argument of the appropriate type
512+ and a second object of an arbitrary type. We never do any kind of
513+ coercion.
512514
513- (And yes, eventually we'll rip out cmp() and tp_compare.)
514-
515- The calling conventions are different: tp_compare only gets called with two
516- objects of the appropriate type; tp_richcompare gets called with a first
517- argument of the appropriate type and a second object of an arbitrary type.
518- We never do any kind of coercion.
519-
520- The return conventions are also different.
521-
522- The tp_compare slot should return a C int, as follows:
523-
524- -1 if a < b or if an exception occurred
525- 0 if a == b
526- +1 if a > b
527-
528- No other return values are allowed. PyObject_Compare() has the same
529- calling convention.
530-
531- The tp_richcompare slot should return an object, as follows:
515+ The tp_richcompare slot should return an object, as follows:
532516
533517 NULL if an exception occurred
534518 NotImplemented if the requested comparison is not implemented
@@ -544,9 +528,6 @@ PyObject_Bytes(PyObject *v)
544528 comparing the object pointer (i.e. falling back to the base object
545529 implementation).
546530
547- - If three-way comparison is not implemented, it falls back on rich
548- comparison (but not the other way around!).
549-
550531*/
551532
552533/* Map rich comparison operators to their swapped version, e.g. LT <--> GT */
0 commit comments