Mercurial > cpython-lru_cache-weakref
diff Objects/typeobject.c @ 51247:ba94d7c095e8
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.
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Sun, 01 Feb 2009 13:59:22 +0000 |
| parents | 9ca34c18e1bd |
| children | e94578247774 |
line wrap: on
line diff
--- a/Objects/typeobject.c Sun Feb 01 12:13:56 2009 +0000 +++ b/Objects/typeobject.c Sun Feb 01 13:59:22 2009 +0000 @@ -3662,7 +3662,7 @@ 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 @@ { /* 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 @@ 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 =
