]> granicus.if.org Git - python/commitdiff
Merged revisions 70430 via svnmerge from
authorMark Dickinson <dickinsm@gmail.com>
Tue, 17 Mar 2009 18:07:41 +0000 (18:07 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Tue, 17 Mar 2009 18:07:41 +0000 (18:07 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r70430 | mark.dickinson | 2009-03-17 18:01:03 +0000 (Tue, 17 Mar 2009) | 3 lines

  Fix bug in Decimal __format__ method that swapped left and right
  alignment.
........

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

index 3ad80b352950b7ce2b0954d2125c002614b382be..6529cc8d77a70e45299cb702892536a343fb2c33 100644 (file)
@@ -5491,9 +5491,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 114cd5b79008196ba6d44f221a41a14f3e7b4cad..92b029e8edc786b3a7d13c8db6c73274e180e8f6 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 d2757e8ac5fc8bd471b250ea5601cbcff5604c96..74a12b8d799526cb7850dcdf3e8d1c0e0fdaf11b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -89,6 +89,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.