summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-08-27 04:55:52 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-08-27 04:55:52 (GMT)
commit9bfe533c6967e2813420d75d4830de3923db0627 (patch)
treeffbcd3cf8cc8973c899a35f5abbe1d676f221902
parent063606a0d5302d8a5530297a70494a9cad334e83 (diff)
downloadcpython-9bfe533c6967e2813420d75d4830de3923db0627.zip
cpython-9bfe533c6967e2813420d75d4830de3923db0627.tar.gz
cpython-9bfe533c6967e2813420d75d4830de3923db0627.tar.bz2
SF bug #795506: Wrong handling of string format code for float values.
Adding missing support for '%F'. Will backport to 2.3.1.
-rw-r--r--Lib/test/string_tests.py1
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/stringobject.c3
-rw-r--r--Objects/unicodeobject.c3
4 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index 7c98a3b..af171d0 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -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)
diff --git a/Misc/NEWS b/Misc/NEWS
index cc2b858..a132b13 100644
--- 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.
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 31aeaa7..04c9c98 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -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);
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 163976e..7ba9547 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -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);