diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2009-02-01 13:59:22 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2009-02-01 13:59:22 (GMT) |
commit | c008a176afdef8cb7afc0e48a8fb306f986964e8 (patch) | |
tree | 9cfaabad2089cf789a0ea4f0a17420cd28bc16a3 /Objects/object.c | |
parent | f02e0aaafd2476948047f0ce904af947f02d18ea (diff) | |
download | cpython-c008a176afdef8cb7afc0e48a8fb306f986964e8.zip cpython-c008a176afdef8cb7afc0e48a8fb306f986964e8.tar.gz cpython-c008a176afdef8cb7afc0e48a8fb306f986964e8.tar.bz2 |
Issue #1717, continued: remove PyObject_Compare and Py_CmpToRich declarations
from object.h; don't inherit tp_compare slot on subclasses; and raise TypeError
when initializing a type that has a nonzero tp_compare slot. Fix up
comparison-related comments in object.c and code.h.
Diffstat (limited to 'Objects/object.c')
-rw-r--r-- | Objects/object.c | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/Objects/object.c b/Objects/object.c index 85dbd28..49c9852 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -500,35 +500,19 @@ PyObject_Bytes(PyObject *v) 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_compare 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 will be renamed to tp_reserved, and should no + longer be used. Use tp_richcompare instead. See (*) below for practical amendments. - IOW, only cmp() uses tp_compare; 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_compare.) - - The calling conventions are different: tp_compare 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_compare 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 @@ -544,9 +528,6 @@ PyObject_Bytes(PyObject *v) 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 */ |