Skip to content

Commit c2bb534

Browse files
committed
Adding tgl.Peer comparisons, only eq/ne
1 parent 13c22f3 commit c2bb534

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

‎python-types.c

+33-1
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,38 @@ tgl_Peer_repr(tgl_Peer *self)
969969
return ret;
970970
}
971971

972+
PyObject *
973+
tgl_Peer_RichCompare(PyObject *self, PyObject *other, int cmp)
974+
{
975+
PyObject *result = NULL;
976+
977+
if(!PyObject_TypeCheck(other, &tgl_PeerType)) {
978+
result = Py_False;
979+
} else {
980+
if(((tgl_Peer*)self)->peer == NULL ||
981+
((tgl_Peer*)other)->peer == NULL) {
982+
result = Py_False; // If either object is not properly instantiated, compare is false
983+
} else {
984+
switch (cmp) {
985+
case Py_EQ:
986+
result = ((tgl_Peer*)self)->peer->id.id == ((tgl_Peer*)other)->peer->id.id ? Py_True : Py_False;
987+
break;
988+
case Py_NE:
989+
result = ((tgl_Peer*)self)->peer->id.id == ((tgl_Peer*)other)->peer->id.id ? Py_False : Py_True;
990+
break;
991+
case Py_LE:
992+
case Py_GE:
993+
case Py_GT:
994+
case Py_LT:
995+
default:
996+
Py_RETURN_NOTIMPLEMENTED;
997+
}
998+
}
999+
}
1000+
Py_XINCREF(result);
1001+
return result;
1002+
}
1003+
9721004

9731005
PyTypeObject tgl_PeerType = {
9741006
PyVarObject_HEAD_INIT(NULL, 0)
@@ -994,7 +1026,7 @@ PyTypeObject tgl_PeerType = {
9941026
"tgl Peer", /* tp_doc */
9951027
0, /* tp_traverse */
9961028
0, /* tp_clear */
997-
0, /* tp_richcompare */
1029+
(richcmpfunc)tgl_Peer_RichCompare, /* tp_richcompare */
9981030
0, /* tp_weaklistoffset */
9991031
0, /* tp_iter */
10001032
0, /* tp_iternext */

0 commit comments

Comments
 (0)