gh-130664: Treat '0' fill character with align '=' as zero-padding fo… · python/cpython@c113a8e · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Commit c113a8e

Browse files
authored
gh-130664: Treat '0' fill character with align '=' as zero-padding for Fraction's (GH-131067)
1 parent 5c984ae commit c113a8e

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

Lib/fractions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,9 @@ def _format_float_style(self, match):
504504
trim_point = not alternate_form
505505
exponent_indicator = "E" if presentation_type in "EFG" else "e"
506506

507+
if align == '=' and fill == '0':
508+
zeropad = True
509+
507510
# Round to get the digits we need, figure out where to place the point,
508511
# and decide whether to use scientific notation. 'point_pos' is the
509512
# relative to the _end_ of the digit string: that is, it's the number

Lib/test/test_fractions.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,11 +1480,8 @@ def test_format_f_presentation_type(self):
14801480
(F('-1234.5678'), '08,.0f', '-001,235'),
14811481
(F('-1234.5678'), '09,.0f', '-0,001,235'),
14821482
# Corner-case - zero-padding specified through fill and align
1483-
# instead of the zero-pad character - in this case, treat '0' as a
1484-
# regular fill character and don't attempt to insert commas into
1485-
# the filled portion. This differs from the int and float
1486-
# behaviour.
1487-
(F('1234.5678'), '0=12,.2f', '00001,234.57'),
1483+
# instead of the zero-pad character.
1484+
(F('1234.5678'), '0=12,.2f', '0,001,234.57'),
14881485
# Corner case where it's not clear whether the '0' indicates zero
14891486
# padding or gives the minimum width, but there's still an obvious
14901487
# answer to give. We want this to work in case the minimum width
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Handle corner-case for :class:`~fractions.Fraction`'s formatting: treat
2+
zero-padding (preceding the width field by a zero (``'0'``) character) as an
3+
equivalent to a fill character of ``'0'`` with an alignment type of ``'='``,
4+
just as in case of :class:`float`'s.

0 commit comments

Comments
 (0)

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.