]> granicus.if.org Git - python/commitdiff
Issue #6850: Fix bug in Decimal._parse_format_specifier for formats
authorMark Dickinson <dickinsm@gmail.com>
Mon, 7 Sep 2009 16:17:41 +0000 (16:17 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Mon, 7 Sep 2009 16:17:41 +0000 (16:17 +0000)
with no type specifier.

Lib/decimal.py
Lib/test/test_decimal.py
Misc/NEWS

index e7864534dcac585fa3e8e1ee830dfc141522df03..1f5c920d795ea9ba1749653b13f6300cf4a312f9 100644 (file)
@@ -5512,7 +5512,7 @@ def _parse_format_specifier(format_spec, _localeconv=None):
     # if format type is 'g' or 'G' then a precision of 0 makes little
     # sense; convert it to 1.  Same if format type is unspecified.
     if format_dict['precision'] == 0:
-        if format_dict['type'] in 'gG' or format_dict['type'] is None:
+        if format_dict['type'] is None or format_dict['type'] in 'gG':
             format_dict['precision'] = 1
 
     # determine thousands separator, grouping, and decimal separator, and
index 0be901abb13087b5763928cd83a7f4df01cac67c..f7f023d22d0455ab5847d563098021d584380834 100644 (file)
@@ -760,6 +760,9 @@ class DecimalFormatTest(unittest.TestCase):
             (',%', '123.456789', '12,345.6789%'),
             (',e', '123456', '1.23456e+5'),
             (',E', '123456', '1.23456E+5'),
+
+            # issue 6850
+            ('a=-7.0', '0.12345', 'aaaa0.1'),
             ]
         for fmt, d, result in test_values:
             self.assertEqual(format(Decimal(d), fmt), result)
index 94f4399639098db108b00c74f1b13a6a9790c35a..fe281cf0149a3d1eef22b5e246a2b28378c46d23 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -366,6 +366,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #6850: Fix bug in Decimal._parse_format_specifier for formats
+  with no type specifier.
+
 - Issue #4937: plat-mac/bundlebuilder revers to non-existing version.plist
 
 - Issue #6838: Use a list to accumulate the value instead of