We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f5da369 commit fb9dc8dCopy full SHA for fb9dc8d
3 files changed
Lib/fractions.py
@@ -167,12 +167,12 @@ def _round_to_figures(n, d, figures):
167
(?P<alt>\#)?
168
# A '0' that's *not* followed by another digit is parsed as a minimum width
169
# rather than a zeropad flag.
170
- (?P<zeropad>0(?=[0-9]))?
171
- (?P<minimumwidth>[0-9]+)?
+ (?P<zeropad>0(?=\d))?
+ (?P<minimumwidth>\d+)?
172
(?P<thousands_sep>[,_])?
173
(?:\.
174
- (?=[,_0-9]) # lookahead for digit or separator
175
- (?P<precision>[0-9]+)?
+ (?=[\d,_]) # lookahead for digit or separator
+ (?P<precision>\d+)?
176
(?P<frac_separators>[,_])?
177
)?
178
(?P<presentation_type>[eEfFgG%])
Lib/test/test_fractions.py
@@ -1326,6 +1326,8 @@ def test_format_e_presentation_type(self):
1326
(F('1234567.123456'), '.5_e', '1.234_57e+06'),
1327
# z flag is legal, but never makes a difference to the output
1328
(F(-1, 7**100), 'z.6e', '-3.091690e-85'),
1329
+ # Accept unicode in width and precision
1330
+ (F(22, 7), '١١.٦e', '3.142857e+00'),
1331
]
1332
for fraction, spec, expected in testcases:
1333
with self.subTest(fraction=fraction, spec=spec):
@@ -1525,6 +1527,8 @@ def test_format_f_presentation_type(self):
1525
1527
(F(151, 1000), '.1f', '0.2'),
1526
1528
(F(22, 7), '.02f', '3.14'), # issue gh-130662
1529
(F(22, 7), '005.02f', '03.14'),
1530
1531
+ (F(22, 7), '٧.٢f', ' 3.14'),
1532
1533
1534
Misc/NEWS.d/next/Library/2025-10-27-09-36-13.gh-issue-135025.fIkmSz.rst
@@ -0,0 +1,2 @@
1
+Allow unicode digits for width and precision fields of format specifications
2
+of :class:`fractions.Fraction`. Patch by Sergey B Kirpichev.
0 commit comments