mp.c: Use implicit-conversion rules in `coerce'.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 24 Nov 2019 00:24:57 +0000 (00:24 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 11 Apr 2020 11:49:31 +0000 (12:49 +0100)
Coercion is only used (in `Py_TPFLAGS_CHECKTYPES' classes) in the three-
way comparison function; but that's still relevant in Python 2.

mp.c
t/t-convert.py

diff --git a/mp.c b/mp.c
index c47b011..163e690 100644 (file)
--- a/mp.c
+++ b/mp.c
@@ -546,7 +546,7 @@ static PyObject *mp_pyfloat(PyObject *x)
       Py_INCREF(*x); Py_INCREF(*y);                                    \
       return (0);                                                      \
     }                                                                  \
-    if ((z = tomp(*y)) != 0) {                                         \
+    if ((z = implicit##pre(*y)) != 0) {                                        \
       Py_INCREF(*x);                                                   \
       *y = pre##_pywrap(z);                                            \
       return (0);                                                      \
index df80617..a5f7ff0 100644 (file)
@@ -91,6 +91,8 @@ class TestConvert (U.TestCase):
     ## `MP' and `GF'.
     me.assertEqual(C.MP(5), 5)
     me.assertEqual(5, C.MP(5))
+    me.assertNotEqual(C.MP(5), C.GF(5))
+    me.assertNotEqual(C.GF(5), C.MP(5))
 
     me.assertEqual(C.MP(5) + 3, 8)
     me.assertEqual(3 + C.MP(5), 8)