gh-130664: support '_' (just as ',') in Decimal's formatting (#132155)

This commit is contained in:
Sergey B Kirpichev 2025-04-15 13:38:03 +03:00 committed by GitHub
parent c66ffcf8e3
commit e10fe81cc6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 1 deletions

View file

@ -6098,7 +6098,7 @@ _parse_format_specifier_regex = re.compile(r"""\A
(?P<alt>\#)?
(?P<zeropad>0)?
(?P<minimumwidth>(?!0)\d+)?
(?P<thousands_sep>,)?
(?P<thousands_sep>[,_])?
(?:\.(?P<precision>0|(?!0)\d+))?
(?P<type>[eEfFgGn%])?
\Z

View file

@ -1083,6 +1083,11 @@ class FormatTest:
(',%', '123.456789', '12,345.6789%'),
(',e', '123456', '1.23456e+5'),
(',E', '123456', '1.23456E+5'),
# ... with '_' instead
('_', '1234567', '1_234_567'),
('07_', '1234.56', '1_234.56'),
('_', '1.23456789', '1.23456789'),
('_%', '123.456789', '12_345.6789%'),
# negative zero: default behavior
('.1f', '-0', '-0.0'),

View file

@ -0,0 +1,2 @@
Support the ``'_'`` digit separator in formatting of the integral part of
:class:`~decimal.Decimal`'s. Patch by Sergey B Kirpichev.