]> granicus.if.org Git - python/commitdiff
Issue 22090: Fix '%' formatting for infinities and NaNs.
authorStefan Krah <skrah@bytereef.org>
Tue, 26 Aug 2014 18:49:57 +0000 (20:49 +0200)
committerStefan Krah <skrah@bytereef.org>
Tue, 26 Aug 2014 18:49:57 +0000 (20:49 +0200)
Lib/decimal.py
Lib/test/test_decimal.py

index 04bf5c266054777d1574d047fa490ac234fddd75..19cc50f9dbb07994e0203b1523ceea40ecace8d3 100644 (file)
@@ -3665,6 +3665,8 @@ class Decimal(object):
         if self._is_special:
             sign = _format_sign(self._sign, spec)
             body = str(self.copy_abs())
+            if spec['type'] == '%':
+                body += '%'
             return _format_align(sign, body, spec)
 
         # a type of None defaults to 'g' or 'G', depending on context
index 09022786ecbe81bde7f87e9dc2bd51a2fc3f4fa9..610a696076128880516e8dc492a4ead634761033 100644 (file)
@@ -823,6 +823,11 @@ class DecimalFormatTest(unittest.TestCase):
 
             # issue 6850
             ('a=-7.0', '0.12345', 'aaaa0.1'),
+
+            # issue 22090
+            ('<^+15.20%', 'inf', '<<+Infinity%<<<'),
+            ('\x07>,%', 'sNaN1234567', 'sNaN1234567%'),
+            ('=10.10%', 'NaN123', '   NaN123%'),
             ]
         for fmt, d, result in test_values:
             self.assertEqual(format(Decimal(d), fmt), result)