diff options
author | Stefan Krah <skrah@bytereef.org> | 2014-08-26 18:49:57 (GMT) |
---|---|---|
committer | Stefan Krah <skrah@bytereef.org> | 2014-08-26 18:49:57 (GMT) |
commit | ce2ec49d92b4c31b6ad358402d8a124e7b03e239 (patch) | |
tree | 0764b573d13aebb418da0a81577018452ae57ce6 /Lib | |
parent | ec9d547edde95783b170cec799e110839a684085 (diff) | |
download | cpython-ce2ec49d92b4c31b6ad358402d8a124e7b03e239.zip cpython-ce2ec49d92b4c31b6ad358402d8a124e7b03e239.tar.gz cpython-ce2ec49d92b4c31b6ad358402d8a124e7b03e239.tar.bz2 |
Issue 22090: Fix '%' formatting for infinities and NaNs.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/decimal.py | 2 | ||||
-rw-r--r-- | Lib/test/test_decimal.py | 5 |
2 files changed, 7 insertions, 0 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py index 04bf5c2..19cc50f 100644 --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -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 diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py index 0902278..610a696 100644 --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -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) |