[Python-checkins] CVS: python/dist/src/Objects complexobject.c,2.47,2.48
Guido van Rossum
gvanrossum@users.sourceforge.net
Mon, 24 Sep 2001 10:52:07 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv24951/Objects
Modified Files:
complexobject.c
Log Message:
Do the same thing to complex that I did to str: the rich comparison
function returns NotImplemented when comparing objects whose
tp_richcompare slot is not itself.
Index: complexobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/complexobject.c,v
retrieving revision 2.47
retrieving revision 2.48
diff -C2 -d -r2.47 -r2.48
*** complexobject.c 2001/09/20 20:46:18 2.47
--- complexobject.c 2001/09/24 17:52:04 2.48
***************
*** 554,563 ****
PyObject *res;
- if (op != Py_EQ && op != Py_NE) {
- PyErr_SetString(PyExc_TypeError,
- "cannot compare complex numbers using <, <=, >, >=");
- return NULL;
- }
-
c = PyNumber_CoerceEx(&v, &w);
if (c < 0)
--- 554,557 ----
***************
*** 567,571 ****
return Py_NotImplemented;
}
! if (!PyComplex_Check(v) || !PyComplex_Check(w)) {
Py_DECREF(v);
Py_DECREF(w);
--- 561,568 ----
return Py_NotImplemented;
}
! /* May sure both arguments use complex comparison.
! This implies PyComplex_Check(a) && PyComplex_Check(b). */
! if (v->ob_type->tp_richcompare != complex_richcompare ||
! w->ob_type->tp_richcompare != complex_richcompare) {
Py_DECREF(v);
Py_DECREF(w);
***************
*** 578,581 ****
--- 575,584 ----
Py_DECREF(v);
Py_DECREF(w);
+
+ if (op != Py_EQ && op != Py_NE) {
+ PyErr_SetString(PyExc_TypeError,
+ "cannot compare complex numbers using <, <=, >, >=");
+ return NULL;
+ }
if ((i.real == j.real && i.imag == j.imag) == (op == Py_EQ))