Add additional coercion support for "self subtypes" to int, long,
float (compare the recent checkin to complex). Added tests for these.
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index b9a5e1b..2de5535 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -590,6 +590,11 @@
Py_INCREF(*pv);
return 0;
}
+ else if (PyFloat_Check(*pw)) {
+ Py_INCREF(*pv);
+ Py_INCREF(*pw);
+ return 0;
+ }
return 1; /* Can't do it */
}
diff --git a/Objects/intobject.c b/Objects/intobject.c
index 16e4336..bb5ad16 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -782,6 +782,17 @@
return PyInt_FromLong(a | b);
}
+static int
+int_coerce(PyObject **pv, PyObject **pw)
+{
+ if (PyInt_Check(*pw)) {
+ Py_INCREF(*pv);
+ Py_INCREF(*pw);
+ return 0;
+ }
+ return 1; /* Can't do it */
+}
+
static PyObject *
int_int(PyIntObject *v)
{
@@ -904,7 +915,7 @@
(binaryfunc)int_and, /*nb_and*/
(binaryfunc)int_xor, /*nb_xor*/
(binaryfunc)int_or, /*nb_or*/
- 0, /*nb_coerce*/
+ int_coerce, /*nb_coerce*/
(unaryfunc)int_int, /*nb_int*/
(unaryfunc)int_long, /*nb_long*/
(unaryfunc)int_float, /*nb_float*/
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 1e01bf0..8f7d9e4 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -2134,6 +2134,11 @@
Py_INCREF(*pv);
return 0;
}
+ else if (PyLong_Check(*pw)) {
+ Py_INCREF(*pv);
+ Py_INCREF(*pw);
+ return 0;
+ }
return 1; /* Can't do it */
}