summaryrefslogtreecommitdiffstats
path: root/Objects/complexobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-09-24 17:52:04 (GMT)
committerGuido van Rossum <guido@python.org>2001-09-24 17:52:04 (GMT)
commit2205642fe0af9c00bbfa713dae1c8ba4562d2236 (patch)
tree4dadb02c974dad9e00ebe1ec1b5a43e12fba18eb /Objects/complexobject.c
parente47df7a2117c14eb5b0445a3002766d54e75278d (diff)
downloadcpython-2205642fe0af9c00bbfa713dae1c8ba4562d2236.zip
cpython-2205642fe0af9c00bbfa713dae1c8ba4562d2236.tar.gz
cpython-2205642fe0af9c00bbfa713dae1c8ba4562d2236.tar.bz2
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.
Diffstat (limited to 'Objects/complexobject.c')
-rw-r--r--Objects/complexobject.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index 191dcba..32f2b24 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -553,12 +553,6 @@ complex_richcompare(PyObject *v, PyObject *w, int op)
Py_complex i, j;
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)
return NULL;
@@ -566,7 +560,10 @@ complex_richcompare(PyObject *v, PyObject *w, int op)
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
- if (!PyComplex_Check(v) || !PyComplex_Check(w)) {
+ /* 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);
Py_INCREF(Py_NotImplemented);
@@ -578,6 +575,12 @@ complex_richcompare(PyObject *v, PyObject *w, int op)
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))
res = Py_True;
else