From: Raymond Hettinger Date: Sat, 31 Aug 2002 15:51:04 +0000 (+0000) Subject: Added comparison functions to dict proxies. X-Git-Tag: v2.3c1~4244 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=29a6d449ef8ea42009215318f8d43a569aed2cf7;p=thirdparty%2FPython%2Fcpython.git Added comparison functions to dict proxies. Now all non-mutating dict methods are in the proxy also. Inspired by SF bug #602232, --- diff --git a/Objects/descrobject.c b/Objects/descrobject.c index fc9d9a1eaa35..63e94e878b86 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 */