diff options
author | Eric Smith <eric@trueblade.com> | 2008-01-28 10:59:27 (GMT) |
---|---|---|
committer | Eric Smith <eric@trueblade.com> | 2008-01-28 10:59:27 (GMT) |
commit | fa767efe0662c7927e644747fa08c083f01b0653 (patch) | |
tree | 2c2ba9c96d8674069386f8c854b6c73776c3e5b1 /Objects | |
parent | fe82e774ea203de277968216126e26d0d09b3a15 (diff) | |
download | cpython-fa767efe0662c7927e644747fa08c083f01b0653.zip cpython-fa767efe0662c7927e644747fa08c083f01b0653.tar.gz cpython-fa767efe0662c7927e644747fa08c083f01b0653.tar.bz2 |
Partially revert r60376: restore ability for ints to be automatically converted to floats, if a float type specifier is given to an int. PEP 3101 should be clarified on this point.Also, remove unused local variables left over from r60376.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/stringlib/formatter.h | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/Objects/stringlib/formatter.h b/Objects/stringlib/formatter.h index 49b3566..2ff7290 100644 --- a/Objects/stringlib/formatter.h +++ b/Objects/stringlib/formatter.h @@ -764,7 +764,6 @@ PyObject * FORMAT_STRING(PyObject* value, PyObject* args) { PyObject *format_spec; - PyObject *tmp = NULL; PyObject *result = NULL; InternalFormatSpec format; @@ -796,7 +795,6 @@ FORMAT_STRING(PyObject* value, PyObject* args) } done: - Py_XDECREF(tmp); return result; } @@ -834,6 +832,21 @@ FORMAT_LONG(PyObject* value, PyObject* args) result = format_long_internal(value, &format); break; + case 'e': + case 'E': + case 'f': + case 'F': + case 'g': + case 'G': + case 'n': + case '%': + /* convert to float */ + tmp = PyNumber_Float(value); + if (tmp == NULL) + goto done; + result = format_float_internal(value, &format); + break; + default: /* unknown */ PyErr_Format(PyExc_ValueError, "Unknown conversion type %c", @@ -851,7 +864,6 @@ FORMAT_FLOAT(PyObject *value, PyObject *args) { PyObject *format_spec; PyObject *result = NULL; - PyObject *tmp = NULL; InternalFormatSpec format; if (!PyArg_ParseTuple(args, STRINGLIB_PARSE_CODE ":__format__", &format_spec)) @@ -890,6 +902,5 @@ FORMAT_FLOAT(PyObject *value, PyObject *args) } done: - Py_XDECREF(tmp); return result; } |