[Python-checkins] r67870 - python/branches/py3k-issue1717/Objects/object.c
mark.dickinson
python-checkins at python.org
Sat Dec 20 12:11:05 CET 2008
Author: mark.dickinson
Date: Sat Dec 20 12:11:05 2008
New Revision: 67870
Log:
Update comments in object.c.
Modified:
python/branches/py3k-issue1717/Objects/object.c
Modified: python/branches/py3k-issue1717/Objects/object.c
==============================================================================
--- python/branches/py3k-issue1717/Objects/object.c (original)
+++ python/branches/py3k-issue1717/Objects/object.c Sat Dec 20 12:11:05 2008
@@ -492,35 +492,19 @@
return PyBytes_FromObject(v);
}
-/* The new comparison philosophy is: we completely separate three-way
- comparison from rich comparison. That is, PyObject_Compare() and
- PyObject_Cmp() *just* use the tp_reserved slot. And PyObject_RichCompare()
- and PyObject_RichCompareBool() *just* use the tp_richcompare slot.
+/* For Python 3.0.1 and later, the old three-way comparison has been
+ completely removed in favour of rich comparisons. PyObject_Compare() and
+ PyObject_Cmp() are gone, and the builtin cmp function no longer exists.
+ The old tp_compare slot has been renamed to tp_reserved, and should no
+ longer be used. Use tp_richcompare instead.
See (*) below for practical amendments.
- IOW, only cmp() uses tp_reserved; the comparison operators (==, !=, <=, <,
- >=, >) only use tp_richcompare. Note that list.sort() only uses <.
+ tp_richcompare gets called with a first argument of the appropriate type
+ and a second object of an arbitrary type. We never do any kind of
+ coercion.
- (And yes, eventually we'll rip out cmp() and tp_reserved.)
-
- The calling conventions are different: tp_reserved only gets called with two
- objects of the appropriate type; tp_richcompare gets called with a first
- argument of the appropriate type and a second object of an arbitrary type.
- We never do any kind of coercion.
-
- The return conventions are also different.
-
- The tp_reserved slot should return a C int, as follows:
-
- -1 if a < b or if an exception occurred
- 0 if a == b
- +1 if a > b
-
- No other return values are allowed. PyObject_Compare() has the same
- calling convention.
-
- The tp_richcompare slot should return an object, as follows:
+ The tp_richcompare slot should return an object, as follows:
NULL if an exception occurred
NotImplemented if the requested comparison is not implemented
@@ -536,9 +520,6 @@
comparing the object pointer (i.e. falling back to the base object
implementation).
- - If three-way comparison is not implemented, it falls back on rich
- comparison (but not the other way around!).
-
*/
/* Map rich comparison operators to their swapped version, e.g. LT <--> GT */
More information about the Python-checkins
mailing list