Commit 9bfe533c authored by Raymond Hettinger's avatar Raymond Hettinger

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

Adding missing support for '%F'.

Will backport to 2.3.1.
parent 063606a0
...@@ -550,6 +550,7 @@ class MixinStrUnicodeUserStringTest: ...@@ -550,6 +550,7 @@ class MixinStrUnicodeUserStringTest:
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)
......
...@@ -12,6 +12,9 @@ What's New in Python 2.4 alpha 1? ...@@ -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.
......
...@@ -3921,8 +3921,11 @@ PyString_Format(PyObject *format, PyObject *args) ...@@ -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);
......
...@@ -6540,8 +6540,11 @@ PyObject *PyUnicode_Format(PyObject *format, ...@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment