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.
This commit is contained in:
Mark Dickinson 2009-02-01 13:59:22 +00:00
parent f02e0aaafd
commit c008a176af
5 changed files with 24 additions and 38 deletions

View file

@ -3662,7 +3662,7 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base)
type->tp_setattr = base->tp_setattr;
type->tp_setattro = base->tp_setattro;
}
/* tp_compare see tp_richcompare */
/* tp_compare is ignored, see tp_richcompare */
COPYSLOT(tp_repr);
/* tp_hash see tp_richcompare */
COPYSLOT(tp_call);
@ -3670,12 +3670,10 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base)
{
/* Copy comparison-related slots only when
not overriding them anywhere */
if (type->tp_compare == NULL &&
type->tp_richcompare == NULL &&
if (type->tp_richcompare == NULL &&
type->tp_hash == NULL &&
!overrides_hash(type))
{
type->tp_compare = base->tp_compare;
type->tp_richcompare = base->tp_richcompare;
type->tp_hash = base->tp_hash;
}
@ -3888,6 +3886,13 @@ PyType_Ready(PyTypeObject *type)
goto error;
}
/* Check reserved slots */
if (type->tp_compare) {
PyErr_Format(PyExc_TypeError,
"type %s has tp_compare",
type->tp_name);
}
/* All done -- set the ready flag */
assert(type->tp_dict != NULL);
type->tp_flags =