[Python-checkins] r74723 - in python/trunk: Lib/decimal.py Lib/test/test_decimal.py Misc/NEWS

mark.dickinson python-checkins at python.org
Tue Sep 8 22:20:19 CEST 2009


Author: mark.dickinson
Date: Tue Sep  8 22:20:19 2009
New Revision: 74723

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


Modified:
   python/trunk/Lib/decimal.py
   python/trunk/Lib/test/test_decimal.py
   python/trunk/Misc/NEWS

Modified: python/trunk/Lib/decimal.py
==============================================================================
--- python/trunk/Lib/decimal.py	(original)
+++ python/trunk/Lib/decimal.py	Tue Sep  8 22:20:19 2009
@@ -5497,7 +5497,10 @@
             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:

Modified: python/trunk/Lib/test/test_decimal.py
==============================================================================
--- python/trunk/Lib/test/test_decimal.py	(original)
+++ python/trunk/Lib/test/test_decimal.py	Tue Sep  8 22:20:19 2009
@@ -712,6 +712,7 @@
             ('', '1.00', '1.00'),
 
             # test alignment and padding
+            ('6', '123', '   123'),
             ('<6', '123', '123   '),
             ('>6', '123', '   123'),
             ('^6', '123', ' 123  '),
@@ -741,7 +742,7 @@
             (',', '-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'),

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Tue Sep  8 22:20:19 2009
@@ -366,6 +366,9 @@
 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')).


More information about the Python-checkins mailing list