Index: Objects/abstract.c =================================================================== --- Objects/abstract.c (révision 70674) +++ Objects/abstract.c (copie de travail) @@ -1618,7 +1618,18 @@ if (m && m->nb_int) { /* This should include subclasses of int */ /* Classic classes always take this branch. */ PyObject *res = m->nb_int(o); - if (res && (!PyInt_Check(res) && !PyLong_Check(res))) { + if (res == NULL) + return NULL; + if (PyLong_Check(res)) { + long value; + value = PyLong_AsLong(res); + if (value != -1 || !PyErr_Occurred()) { + Py_DECREF(res); + res = PyInt_FromLong(value); + } else { + PyErr_Clear(); + } + } else if (!PyInt_Check(res)) { PyErr_Format(PyExc_TypeError, "__int__ returned non-int (type %.200s)", res->ob_type->tp_name); Index: Objects/obmalloc.c =================================================================== --- Objects/obmalloc.c (révision 70674) +++ Objects/obmalloc.c (copie de travail) @@ -677,8 +677,8 @@ /* This is only useful when running memory debuggers such as * Purify or Valgrind. Uncomment to use. * -#define Py_USING_MEMORY_DEBUGGER */ +#define Py_USING_MEMORY_DEBUGGER #ifdef Py_USING_MEMORY_DEBUGGER Index: Lib/test/test_int.py =================================================================== --- Lib/test/test_int.py (révision 70674) +++ Lib/test/test_int.py (copie de travail) @@ -359,6 +359,21 @@ self.fail("Failed to raise TypeError with %s" % ((base, trunc_result_base),)) + def test_type(self): + maxint = sys.maxsize + minint = -maxint - 1 + class Integer: + def __init__(self, value): + self.value = value + def __int__(self): + return long(self.value) + def test_type(value): + return type(int(Integer(value))) + self.assertEquals(test_type(maxint), int) + self.assertEquals(test_type(maxint + 1), long) + self.assertEquals(test_type(minint), int) + self.assertEquals(test_type(minint - 1), long) + def test_main(): run_unittest(IntTestCases)