]> granicus.if.org Git - python/commitdiff
Issue #6857: Fix Decimal formatting to be consistent with existing float
authorMark Dickinson <dickinsm@gmail.com>
Tue, 8 Sep 2009 20:20:19 +0000 (20:20 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Tue, 8 Sep 2009 20:20:19 +0000 (20:20 +0000)
formatting:  both are now right-aligned by default.

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

index a87a4a541101345d687ea334c0bd7e4ecf0c634f..4d1f7f9f152a3495c677ea134d7db267b87f1358 100644 (file)
@@ -5497,7 +5497,10 @@ def _parse_format_specifier(format_spec, _localeconv=None):
             raise ValueError("Alignment conflicts with '0' in "
                              "format specifier: " + format_spec)
     format_dict['fill'] = fill or ' '
-    format_dict['align'] = align or '<'
+    # PEP 3101 originally specified that the default alignment should
+    # be left;  it was later agreed that right-aligned makes more sense
+    # for numeric types.  See http://bugs.python.org/issue6857.
+    format_dict['align'] = align or '>'
 
     # default sign handling: '-' for negative, '' for positive
     if format_dict['sign'] is None:
index 50a855e9d1df622b45cde5baa37a5bdd23af22d9..01282315c66e698f5f79abeeba30168ccff92ee5 100644 (file)
@@ -712,6 +712,7 @@ class DecimalFormatTest(unittest.TestCase):
             ('', '1.00', '1.00'),
 
             # test alignment and padding
+            ('6', '123', '   123'),
             ('<6', '123', '123   '),
             ('>6', '123', '   123'),
             ('^6', '123', ' 123  '),
@@ -741,7 +742,7 @@ class DecimalFormatTest(unittest.TestCase):
             (',', '-1234567', '-1,234,567'),
             (',', '-123456', '-123,456'),
             ('7,', '123456', '123,456'),
-            ('8,', '123456', '123,456 '),
+            ('8,', '123456', ' 123,456'),
             ('08,', '123456', '0,123,456'), # special case: extra 0 needed
             ('+08,', '123456', '+123,456'), # but not if there's a sign
             (' 08,', '123456', ' 123,456'),
index daea539f8c65a0052183729ae1de80e69746ad0e..3c1c54e41151c463017752ed918b80ffd46b4e91 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -366,6 +366,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #6857: Default format() alignment should be '>' for Decimal
+  instances.
+
 - Issue #6795: int(Decimal('nan')) now raises ValueError instead of
   returning NaN or raising InvalidContext.  Also, fix infinite recursion
   in long(Decimal('nan')).