]> granicus.if.org Git - python/commitdiff
Merged revisions 74723 via svnmerge from
authorMark Dickinson <dickinsm@gmail.com>
Tue, 8 Sep 2009 20:22:46 +0000 (20:22 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Tue, 8 Sep 2009 20:22:46 +0000 (20:22 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r74723 | mark.dickinson | 2009-09-08 21:20:19 +0100 (Tue, 08 Sep 2009) | 3 lines

  Issue #6857: Fix Decimal formatting to be consistent with existing float
  formatting:  both are now right-aligned by default.
........

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

index e3fa8cb84fa21ecc21d34bd69447866303b14a7c..33f539178be8b3ea46130d14059c5076a1c6d534 100644 (file)
@@ -5577,7 +5577,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 e3e50f070761a2c4fc396aaee5385e19b6c794c3..39a0ad57ad8b0daaf4d966ea9e712dde1995f3cd 100644 (file)
@@ -701,6 +701,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  '),
@@ -730,7 +731,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 c1b1775cb6765f57123e601cb63945420732f332..a1def5c565c2f33008311d1358672db5e60d349f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -70,6 +70,9 @@ C-API
 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')).