%d with long numbers Fecha:25/06/2007 2:38:33 Directorio base izquierdo: C:\APPS\PYTHON25\Python-2.5.1-original Directorio base derecho: C:\APPS\PYTHON25\Python-2.5.1 --- Lib\test\string_tests.py 2006-09-04 23:21:38.000000000 -0300 +++ Lib\test\string_tests.py 2007-05-26 12:59:30.000000000 -0300 @@ -992,0 +993,4 @@ + longvalue = sys.maxint + 10L + slongvalue = str(longvalue) + if slongvalue[-1] in ("L","l"): slongvalue = slongvalue[:-1] + @@ -993,0 +998,4 @@ + self.checkequal('42', '%d', '__mod__', 42L) + self.checkequal('42', '%d', '__mod__', 42.0) + self.checkequal(slongvalue, '%d', '__mod__', longvalue) + self.checkcall('%d', '__mod__', float(longvalue)) @@ -1002,0 +1011,2 @@ + self.checkraises(TypeError, '%d', '__mod__', "42") # not numeric + self.checkraises(TypeError, '%d', '__mod__', (42+0j)) # no int/long conversion provided --- Objects\stringobject.c 2007-02-26 10:51:34.000000000 -0300 +++ Objects\stringobject.c 2007-05-26 11:45:54.000000000 -0300 @@ -4686 +4687,33 @@ - if (PyLong_Check(v)) { + if (PyNumber_Check(v) && !PyLong_Check(v) && !PyInt_Check(v)) { + PyObject *io=NULL; + + io = PyNumber_Int(v); + if (io==NULL) io = PyNumber_Long(v); + if ((io!=NULL) && PyInt_Check(io)) { + pbuf = formatbuf; + len = formatint(pbuf, + sizeof(formatbuf), + flags, prec, c, io); + Py_DECREF(io); + if (len < 0) + goto error; + sign = 1; + } + else if ((io!=NULL) && PyLong_Check(io)) { + int ilen; + temp = _PyString_FormatLong(io, flags, + prec, c, &pbuf, &ilen); + Py_DECREF(io); + len = ilen; + if (!temp) + goto error; + sign = 1; + } + else { + Py_XDECREF(io); + PyErr_SetString(PyExc_TypeError, + "%d format: an integer or long is required"); + goto error; + } + } + else if (PyLong_Check(v)) { --- Objects\unicodeobject.c 2006-10-04 08:44:06.000000000 -0300 +++ Objects\unicodeobject.c 2007-05-26 11:46:26.000000000 -0300 @@ -7714 +7715,31 @@ - if (PyLong_Check(v)) { + if (PyNumber_Check(v) && !PyLong_Check(v) && !PyInt_Check(v)) { + PyObject *io=NULL; + + io = PyNumber_Int(v); + if (io==NULL) io = PyNumber_Long(v); + if ((io!=NULL) && PyInt_Check(io)) { + pbuf = formatbuf; + len = formatint(pbuf, sizeof(formatbuf)/sizeof(Py_UNICODE), + flags, prec, c, io); + Py_DECREF(io); + if (len < 0) + goto onError; + sign = 1; + } + else if ((io!=NULL) && PyLong_Check(io)) { + temp = formatlong(io, flags, prec, c); + Py_DECREF(io); + if (!temp) + goto onError; + pbuf = PyUnicode_AS_UNICODE(temp); + len = PyUnicode_GET_SIZE(temp); + sign = 1; + } + else { + Py_XDECREF(io); + PyErr_SetString(PyExc_TypeError, + "%d format: an integer or long is required"); + goto onError; + } + } + else if (PyLong_Check(v)) {