[3.13] gh-130664: support '_' (just as ',') in Decimal's formatting (GH-132155) (#136649)
Some checks are pending
Tests / (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Docs (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Check if the ABI has changed (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run

gh-130664: support '_' (just as ',') in Decimal's formatting (GH-132155)
(cherry picked from commit e10fe81cc6)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
This commit is contained in:
Miss Islington (bot) 2025-07-14 14:01:49 +02:00 committed by GitHub
parent 2115e71ea5
commit 2a6617de48
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 1 deletions

View file

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

View file

@ -1059,6 +1059,11 @@ class FormatTest:
(',%', '123.456789', '12,345.6789%'), (',%', '123.456789', '12,345.6789%'),
(',e', '123456', '1.23456e+5'), (',e', '123456', '1.23456e+5'),
(',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 # negative zero: default behavior
('.1f', '-0', '-0.0'), ('.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.