]> granicus.if.org Git - python/commitdiff
SF bug #795506: Wrong handling of string format code for float values.
authorRaymond Hettinger <python@rcn.com>
Wed, 27 Aug 2003 04:55:52 +0000 (04:55 +0000)
committerRaymond Hettinger <python@rcn.com>
Wed, 27 Aug 2003 04:55:52 +0000 (04:55 +0000)
Adding missing support for '%F'.

Will backport to 2.3.1.

Lib/test/string_tests.py
Misc/NEWS
Objects/stringobject.c
Objects/unicodeobject.c

index 7c98a3bb8c840bc4b5797902feef535faeb6ce06..af171d08ab3fc6e49c1449b65f6c1beebb4cad90 100644 (file)
@@ -550,6 +550,7 @@ class MixinStrUnicodeUserStringTest:
 
         self.checkequal(' 42', '%3ld', '__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, '%(foo)s', '__mod__', 42)
index cc2b858ff5feaa23b1bbe52be2ea63f2803ce40e..a132b13d0c39890c3d99fcef10d62843b9a5ad10 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.4 alpha 1?
 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
   number.
 
index 31aeaa7c741633b2b3037c74e87f44ed7ef8e5e3..04c9c9887a2bf050b7774dc2ed98687c5e393806 100644 (file)
@@ -3921,8 +3921,11 @@ PyString_Format(PyObject *format, PyObject *args)
                        case 'e':
                        case 'E':
                        case 'f':
+                       case 'F':
                        case 'g':
                        case 'G':
+                               if (c == 'F')
+                                       c = 'f';
                                pbuf = formatbuf;
                                len = formatfloat(pbuf, sizeof(formatbuf),
                                                  flags, prec, c, v);
index 163976e952b7538a55cf5e5728698907e774383f..7ba9547b1f747b8f23a663c9cbda8bb72b2c5567 100644 (file)
@@ -6540,8 +6540,11 @@ PyObject *PyUnicode_Format(PyObject *format,
            case 'e':
            case 'E':
            case 'f':
+           case 'F':
            case 'g':
            case 'G':
+               if (c == 'F')
+                       c = 'f';
                pbuf = formatbuf;
                len = formatfloat(pbuf, sizeof(formatbuf)/sizeof(Py_UNICODE),
                        flags, prec, c, v);