SF bug #795506: Wrong handling of string format code for float values.

Adding missing support for '%F'.

Will backport to 2.3.1.
This commit is contained in:
Raymond Hettinger 2003-08-27 04:55:52 +00:00
parent 063606a0d5
commit 9bfe533c69
4 changed files with 10 additions and 0 deletions

View File

@ -550,6 +550,7 @@ def test_formatting(self):
self.checkequal(' 42', '%3ld', '__mod__', 42) self.checkequal(' 42', '%3ld', '__mod__', 42)
self.checkequal('0042.00', '%07.2f', '__mod__', 42) self.checkequal('0042.00', '%07.2f', '__mod__', 42)
self.checkequal('0042.00', '%07.2F', '__mod__', 42)
self.checkraises(TypeError, 'abc', '__mod__') self.checkraises(TypeError, 'abc', '__mod__')
self.checkraises(TypeError, '%(foo)s', '__mod__', 42) self.checkraises(TypeError, '%(foo)s', '__mod__', 42)

View File

@ -12,6 +12,9 @@ What's New in Python 2.4 alpha 1?
Core and builtins Core and builtins
----------------- -----------------
- The % formatting operator now supports '%F' which is equivalent to
'%f'. This has always been documented but never implemented.
- complex(obj) could leak a little memory if obj wasn't a string or - complex(obj) could leak a little memory if obj wasn't a string or
number. number.

View File

@ -3921,8 +3921,11 @@ PyString_Format(PyObject *format, PyObject *args)
case 'e': case 'e':
case 'E': case 'E':
case 'f': case 'f':
case 'F':
case 'g': case 'g':
case 'G': case 'G':
if (c == 'F')
c = 'f';
pbuf = formatbuf; pbuf = formatbuf;
len = formatfloat(pbuf, sizeof(formatbuf), len = formatfloat(pbuf, sizeof(formatbuf),
flags, prec, c, v); flags, prec, c, v);

View File

@ -6540,8 +6540,11 @@ PyObject *PyUnicode_Format(PyObject *format,
case 'e': case 'e':
case 'E': case 'E':
case 'f': case 'f':
case 'F':
case 'g': case 'g':
case 'G': case 'G':
if (c == 'F')
c = 'f';
pbuf = formatbuf; pbuf = formatbuf;
len = formatfloat(pbuf, sizeof(formatbuf)/sizeof(Py_UNICODE), len = formatfloat(pbuf, sizeof(formatbuf)/sizeof(Py_UNICODE),
flags, prec, c, v); flags, prec, c, v);