Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Lib/fractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ def _round_to_figures(n, d, figures):
(?P<alt>\#)?
# A '0' that's *not* followed by another digit is parsed as a minimum width
# rather than a zeropad flag.
(?P<zeropad>0(?=[0-9]))?
(?P<minimumwidth>[0-9]+)?
(?P<zeropad>0(?=\d))?
(?P<minimumwidth>\d+)?
(?P<thousands_sep>[,_])?
(?:\.
(?=[,_0-9]) # lookahead for digit or separator
(?P<precision>[0-9]+)?
(?=[\d,_]) # lookahead for digit or separator
(?P<precision>\d+)?
(?P<frac_separators>[,_])?
)?
(?P<presentation_type>[eEfFgG%])
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_fractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,8 @@ def test_format_e_presentation_type(self):
(F('1234567.123456'), '.5_e', '1.234_57e+06'),
# z flag is legal, but never makes a difference to the output
(F(-1, 7**100), 'z.6e', '-3.091690e-85'),
# Accept unicode in width and precision
(F(22, 7), '١١.٦e', '3.142857e+00'),
]
for fraction, spec, expected in testcases:
with self.subTest(fraction=fraction, spec=spec):
Expand Down Expand Up @@ -1525,6 +1527,8 @@ def test_format_f_presentation_type(self):
(F(151, 1000), '.1f', '0.2'),
(F(22, 7), '.02f', '3.14'), # issue gh-130662
(F(22, 7), '005.02f', '03.14'),
# Accept unicode in width and precision
(F(22, 7), '٧.٢f', ' 3.14'),
]
for fraction, spec, expected in testcases:
with self.subTest(fraction=fraction, spec=spec):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Allow unicode digits for width and precision fields of format specifications
of :class:`fractions.Fraction`. Patch by Sergey B Kirpichev.
Loading