py/mpprint: Correctly format leading zeros with separators.

Correctly format integers when there are leading zeros with a grouping
character, such as "{:04,d}".format(0x100) -> "0,256".

The new padding patterns for commas-and-zeroes and underscores-and-zeroes
are smooshed together into the existing pad_zeroes to save space.

Only the two combinations of (decimal + commas) and (other bases +
underscores) are properly supported.

Also add a test for it.

Fixes issue #18082.

Signed-off-by: Jeff Epler <jepler@unpythonic.net>
This commit is contained in:
Jeff Epler
2025-09-17 10:29:54 -05:00
committed by Damien George
parent 01a11ea45e
commit 5552fbe172
2 changed files with 43 additions and 5 deletions

View File

@@ -0,0 +1,9 @@
try:
"%d" % 1
except TypeError:
print("SKIP")
raise SystemExit
for v in (0, 0x10, 0x1000, -0x10, -0x1000):
for sz in range(1, 12): print(("{:0%d,d}" % sz).format(v))
for sz in range(1, 12): print(("{:0%d_x}" % sz).format(v))