]> granicus.if.org Git - python/commitdiff
Fix bug in Decimal __format__ method that swapped left and right
authorMark Dickinson <dickinsm@gmail.com>
Tue, 17 Mar 2009 18:01:03 +0000 (18:01 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Tue, 17 Mar 2009 18:01:03 +0000 (18:01 +0000)
alignment.

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

index 1d12e87b138baa58d932b3ce501b8d84ab2f55a5..2b16e6ab84cbbad232764be5de3f8ef48f0f25ba 100644 (file)
@@ -5551,9 +5551,9 @@ def _format_align(body, spec_dict):
 
     align = spec_dict['align']
     if align == '<':
-        result = padding + sign + body
-    elif align == '>':
         result = sign + body + padding
+    elif align == '>':
+        result = padding + sign + body
     elif align == '=':
         result = sign + padding + body
     else: #align == '^'
index 65aa03322583c3c31c0876b3638db92826190cc0..eed1eed081fd571631466cb1f7a6c6ac2cd2781b 100644 (file)
@@ -704,6 +704,12 @@ class DecimalFormatTest(unittest.TestCase):
             ('.0g', '-sNaN', '-sNaN'),
 
             ('', '1.00', '1.00'),
+
+            # check alignment
+            ('<6', '123', '123   '),
+            ('>6', '123', '   123'),
+            ('^6', '123', ' 123  '),
+            ('=+6', '123', '+  123'),
             ]
         for fmt, d, result in test_values:
             self.assertEqual(format(Decimal(d), fmt), result)
index 943229558584ee70c1aed896f78ebdb3a08a604f..c506071b65fffbbca7d77f313b11a35d69813d87 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -174,6 +174,9 @@ Core and Builtins
 Library
 -------
 
+- Fix Decimal.__format__ bug that swapped the meanings of the '<' and
+  '>' alignment characters.
+
 - Issue #1222: locale.format() bug when the thousands separator is a space
   character.