From 29a6d449ef8ea42009215318f8d43a569aed2cf7 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sat, 31 Aug 2002 15:51:04 +0000 Subject: [PATCH] Added comparison functions to dict proxies. Now all non-mutating dict methods are in the proxy also. Inspired by SF bug #602232, --- Objects/descrobject.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Objects/descrobject.c b/Objects/descrobject.c index fc9d9a1eaa3..63e94e878b8 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -718,6 +718,18 @@ proxy_traverse(PyObject *self, visitproc visit, void *arg) return 0; } +static int +proxy_compare(proxyobject *v, PyObject *w) +{ + return PyObject_Compare(v->dict, w); +} + +static PyObject * +proxy_richcompare(proxyobject *v, PyObject *w, int op) +{ + return PyObject_RichCompare(v->dict, w, op); +} + static PyTypeObject proxytype = { PyObject_HEAD_INIT(&PyType_Type) 0, /* ob_size */ @@ -729,7 +741,7 @@ static PyTypeObject proxytype = { 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_compare */ + (cmpfunc)proxy_compare, /* tp_compare */ 0, /* tp_repr */ 0, /* tp_as_number */ &proxy_as_sequence, /* tp_as_sequence */ @@ -744,7 +756,7 @@ static PyTypeObject proxytype = { 0, /* tp_doc */ proxy_traverse, /* tp_traverse */ 0, /* tp_clear */ - 0, /* tp_richcompare */ + (richcmpfunc)proxy_richcompare, /* tp_richcompare */ 0, /* tp_weaklistoffset */ (getiterfunc)proxy_getiter, /* tp_iter */ 0, /* tp_iternext */