Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
5cfa8044
Commit
5cfa8044
authored
Sep 08, 2009
by
Mark Dickinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #6857: Fix Decimal formatting to be consistent with existing float
formatting: both are now right-aligned by default.
parent
81809a42
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
2 deletions
+9
-2
Lib/decimal.py
Lib/decimal.py
+4
-1
Lib/test/test_decimal.py
Lib/test/test_decimal.py
+2
-1
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/decimal.py
View file @
5cfa8044
...
@@ -5497,7 +5497,10 @@ def _parse_format_specifier(format_spec, _localeconv=None):
...
@@ -5497,7 +5497,10 @@ def _parse_format_specifier(format_spec, _localeconv=None):
raise
ValueError
(
"Alignment conflicts with '0' in "
raise
ValueError
(
"Alignment conflicts with '0' in "
"format specifier: "
+
format_spec
)
"format specifier: "
+
format_spec
)
format_dict
[
'fill'
]
=
fill
or
' '
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
# default sign handling: '-' for negative, '' for positive
if
format_dict
[
'sign'
]
is
None
:
if
format_dict
[
'sign'
]
is
None
:
...
...
Lib/test/test_decimal.py
View file @
5cfa8044
...
@@ -712,6 +712,7 @@ class DecimalFormatTest(unittest.TestCase):
...
@@ -712,6 +712,7 @@ class DecimalFormatTest(unittest.TestCase):
(
''
,
'1.00'
,
'1.00'
),
(
''
,
'1.00'
,
'1.00'
),
# test alignment and padding
# test alignment and padding
(
'6'
,
'123'
,
' 123'
),
(
'<6'
,
'123'
,
'123 '
),
(
'<6'
,
'123'
,
'123 '
),
(
'>6'
,
'123'
,
' 123'
),
(
'>6'
,
'123'
,
' 123'
),
(
'^6'
,
'123'
,
' 123 '
),
(
'^6'
,
'123'
,
' 123 '
),
...
@@ -741,7 +742,7 @@ class DecimalFormatTest(unittest.TestCase):
...
@@ -741,7 +742,7 @@ class DecimalFormatTest(unittest.TestCase):
(
','
,
'-1234567'
,
'-1,234,567'
),
(
','
,
'-1234567'
,
'-1,234,567'
),
(
','
,
'-123456'
,
'-123,456'
),
(
','
,
'-123456'
,
'-123,456'
),
(
'7,'
,
'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'
,
'0,123,456'
),
# special case: extra 0 needed
(
'+08,'
,
'123456'
,
'+123,456'
),
# but not if there's a sign
(
'+08,'
,
'123456'
,
'+123,456'
),
# but not if there's a sign
(
' 08,'
,
'123456'
,
' 123,456'
),
(
' 08,'
,
'123456'
,
' 123,456'
),
...
...
Misc/NEWS
View file @
5cfa8044
...
@@ -366,6 +366,9 @@ Core and Builtins
...
@@ -366,6 +366,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #6857: Default format() alignment should be '>' for Decimal
instances.
- Issue #6795: int(Decimal('nan')) now raises ValueError instead of
- Issue #6795: int(Decimal('nan')) now raises ValueError instead of
returning NaN or raising InvalidContext. Also, fix infinite recursion
returning NaN or raising InvalidContext. Also, fix infinite recursion
in long(Decimal('nan')).
in long(Decimal('nan')).
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment