Skip to content

Commit 18a67ba

Browse files
committed
Fix comparing complex to non-complex numbers.
1 parent 4886cc3 commit 18a67ba

2 files changed

Lines changed: 4 additions & 38 deletions

File tree

BROKEN

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -110,31 +110,3 @@ Traceback (most recent call last):
110110
File "../Lib/test/test_set.py", line 291, in test_remove
111111
self.assert_(self.thetype(self.word) in s)
112112
AssertionError
113-
114-
////////////////////////////////////////////////////////////////////////
115-
test_compare
116-
////////////////////////////////////////////////////////////////////////
117-
test test_compare failed -- Traceback (most recent call last):
118-
File "/Users/nnorwitz/build/python/py3k.2/Lib/test/test_compare.py", line 28, in test_comparisons
119-
self.assertEqual(a, b)
120-
AssertionError: 2 != (2+0j)
121-
122-
////////////////////////////////////////////////////////////////////////
123-
test_complex
124-
////////////////////////////////////////////////////////////////////////
125-
======================================================================
126-
FAIL: test_pow (test.test_complex.ComplexTest)
127-
----------------------------------------------------------------------
128-
Traceback (most recent call last):
129-
File "/Users/nnorwitz/build/python/py3k.2/Lib/test/test_complex.py", line 130, in test_pow
130-
self.assertEqual(a ** 0j, 1)
131-
AssertionError: (1+0j) != 1
132-
133-
======================================================================
134-
FAIL: test_richcompare (test.test_complex.ComplexTest)
135-
----------------------------------------------------------------------
136-
Traceback (most recent call last):
137-
File "/Users/nnorwitz/build/python/py3k.2/Lib/test/test_complex.py", line 96, in test_richcompare
138-
self.assertRaises(OverflowError, complex.__eq__, 1+1j, 1L<<10000)
139-
AssertionError: OverflowError not raised
140-

Objects/complexobject.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -576,19 +576,13 @@ complex_nonzero(PyComplexObject *v)
576576
static PyObject *
577577
complex_richcompare(PyObject *v, PyObject *w, int op)
578578
{
579-
Py_complex i, j;
580579
PyObject *res;
581-
582-
/* Make sure both arguments are complex. */
583-
if (!(PyComplex_Check(v) && PyComplex_Check(w))) {
584-
Py_INCREF(Py_NotImplemented);
585-
return Py_NotImplemented;
586-
}
587-
588-
i = ((PyComplexObject *)v)->cval;
589-
j = ((PyComplexObject *)w)->cval;
580+
Py_complex i, j;
581+
TO_COMPLEX(v, i);
582+
TO_COMPLEX(w, j);
590583

591584
if (op != Py_EQ && op != Py_NE) {
585+
/* XXX Should eventually return NotImplemented */
592586
PyErr_SetString(PyExc_TypeError,
593587
"no ordering relation is defined for complex numbers");
594588
return NULL;

0 commit comments

Comments
 (0)