https://github.com/python/cpython/commit/2a6617de48f3d279e9c5f7971f44dc63a63bf12e
commit: 2a6617de48f3d279e9c5f7971f44dc63a63bf12e
branch: 3.13
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: picnixz <10796600+picn...@users.noreply.github.com>
date: 2025-07-14T14:01:49+02:00
summary:

[3.13] gh-130664: support '_' (just as ',') in Decimal's formatting (GH-132155) 
(#136649)

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

Co-authored-by: Sergey B Kirpichev <skirpic...@gmail.com>

files:
A Misc/NEWS.d/next/Library/2025-04-06-14-34-29.gh-issue-130664.JF2r-U.rst
M Lib/_pydecimal.py
M Lib/test/test_decimal.py

diff --git a/Lib/_pydecimal.py b/Lib/_pydecimal.py
index ff80180a79e97a..8d3a9f7ed45e25 100644
--- a/Lib/_pydecimal.py
+++ b/Lib/_pydecimal.py
@@ -6083,7 +6083,7 @@ def _convert_for_comparison(self, other, 
equality_op=False):
 (?P<alt>\#)?
 (?P<zeropad>0)?
 (?P<minimumwidth>(?!0)\d+)?
-(?P<thousands_sep>,)?
+(?P<thousands_sep>[,_])?
 (?:\.(?P<precision>0|(?!0)\d+))?
 (?P<type>[eEfFgGn%])?
 \Z
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
index 46c50115aef117..23107c603f8d41 100644
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -1059,6 +1059,11 @@ def test_formatting(self):
             (',%', '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'),
diff --git 
a/Misc/NEWS.d/next/Library/2025-04-06-14-34-29.gh-issue-130664.JF2r-U.rst 
b/Misc/NEWS.d/next/Library/2025-04-06-14-34-29.gh-issue-130664.JF2r-U.rst
new file mode 100644
index 00000000000000..294a7e031b2806
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-04-06-14-34-29.gh-issue-130664.JF2r-U.rst
@@ -0,0 +1,2 @@
+Support the ``'_'`` digit separator in formatting of the integral part of
+:class:`~decimal.Decimal`'s.  Patch by Sergey B Kirpichev.

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: arch...@mail-archive.com

Reply via email to