mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
gh-130662: Accept leading zeros in precision/width for Decimal's formatting (#132549)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
parent
5bc2d99126
commit
9c72658e49
3 changed files with 7 additions and 2 deletions
|
@ -6120,9 +6120,9 @@ _parse_format_specifier_regex = re.compile(r"""\A
|
||||||
(?P<no_neg_0>z)?
|
(?P<no_neg_0>z)?
|
||||||
(?P<alt>\#)?
|
(?P<alt>\#)?
|
||||||
(?P<zeropad>0)?
|
(?P<zeropad>0)?
|
||||||
(?P<minimumwidth>(?!0)\d+)?
|
(?P<minimumwidth>\d+)?
|
||||||
(?P<thousands_sep>[,_])?
|
(?P<thousands_sep>[,_])?
|
||||||
(?:\.(?P<precision>0|(?!0)\d+))?
|
(?:\.(?P<precision>\d+))?
|
||||||
(?P<type>[eEfFgGn%])?
|
(?P<type>[eEfFgGn%])?
|
||||||
\z
|
\z
|
||||||
""", re.VERBOSE|re.DOTALL)
|
""", re.VERBOSE|re.DOTALL)
|
||||||
|
|
|
@ -981,6 +981,7 @@ class FormatTest:
|
||||||
('.0f', '0e-2', '0'),
|
('.0f', '0e-2', '0'),
|
||||||
('.0f', '3.14159265', '3'),
|
('.0f', '3.14159265', '3'),
|
||||||
('.1f', '3.14159265', '3.1'),
|
('.1f', '3.14159265', '3.1'),
|
||||||
|
('.01f', '3.14159265', '3.1'), # leading zero in precision
|
||||||
('.4f', '3.14159265', '3.1416'),
|
('.4f', '3.14159265', '3.1416'),
|
||||||
('.6f', '3.14159265', '3.141593'),
|
('.6f', '3.14159265', '3.141593'),
|
||||||
('.7f', '3.14159265', '3.1415926'), # round-half-even!
|
('.7f', '3.14159265', '3.1415926'), # round-half-even!
|
||||||
|
@ -1066,6 +1067,7 @@ class FormatTest:
|
||||||
('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
|
||||||
|
('008,', '123456', '0,123,456'), # leading zero in width
|
||||||
(' 08,', '123456', ' 123,456'),
|
(' 08,', '123456', ' 123,456'),
|
||||||
('08,', '-123456', '-123,456'),
|
('08,', '-123456', '-123,456'),
|
||||||
('+09,', '123456', '+0,123,456'),
|
('+09,', '123456', '+0,123,456'),
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
+Accept leading zeros in precision and width fields for
|
||||||
|
+:class:`~decimal.Decimal` formatting, for example ``format(Decimal(1.25),
|
||||||
|
'.016f')``.
|
Loading…
Add table
Add a link
Reference in a new issue