Make subclasses of int, long, complex, float, and unicode perform type
conversion using the proper magic slot (e.g., __int__()). Also move conversion
code out of PyNumber_*() functions in the C API into the nb_* function.
Applied patch #1109424. Thanks Walter Doewald.
diff --git a/Objects/intobject.c b/Objects/intobject.c
index 763ed53..0ead74b 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -826,7 +826,10 @@
static PyObject *
int_int(PyIntObject *v)
{
- Py_INCREF(v);
+ if (PyInt_CheckExact(v))
+ Py_INCREF(v);
+ else
+ v = (PyIntObject *)PyInt_FromLong(v->ob_ival);
return (PyObject *)v;
}