cpython: 4e55e011dd80 (original) (raw)
--- a/Lib/test/test_format.py +++ b/Lib/test/test_format.py @@ -114,6 +114,7 @@ class FormatTest(unittest.TestCase): testcommon("%o", 100000000000, "1351035564000") testcommon("%d", 10, "10") testcommon("%d", 100000000000, "100000000000") + big = 123456789012345678901234567890 testcommon("%d", big, "123456789012345678901234567890") testcommon("%d", -big, "-123456789012345678901234567890") @@ -133,6 +134,7 @@ class FormatTest(unittest.TestCase): testcommon("%.31d", big, "0123456789012345678901234567890") testcommon("%32.31d", big, " 0123456789012345678901234567890") testcommon("%d", float(big), "123456________________________", 6) + big = 0x1234567890abcdef12345 # 21 hex digits testcommon("%x", big, "1234567890abcdef12345") testcommon("%x", -big, "-1234567890abcdef12345") @@ -156,19 +158,26 @@ class FormatTest(unittest.TestCase): testcommon("%#X", big, "0X1234567890ABCDEF12345") testcommon("%#x", big, "0x1234567890abcdef12345") testcommon("%#x", -big, "-0x1234567890abcdef12345")
testcommon("%#27x", big, " 0x1234567890abcdef12345")[](#l1.23)
testcommon("%#-27x", big, "0x1234567890abcdef12345 ")[](#l1.24)
testcommon("%#027x", big, "0x00001234567890abcdef12345")[](#l1.25)
testcommon("%#.23x", big, "0x001234567890abcdef12345")[](#l1.26) testcommon("%#.23x", -big, "-0x001234567890abcdef12345")[](#l1.27)
testcommon("%#27.23x", big, " 0x001234567890abcdef12345")[](#l1.28)
testcommon("%#-27.23x", big, "0x001234567890abcdef12345 ")[](#l1.29)
testcommon("%#027.23x", big, "0x00001234567890abcdef12345")[](#l1.30) testcommon("%#+.23x", big, "+0x001234567890abcdef12345")[](#l1.31) testcommon("%# .23x", big, " 0x001234567890abcdef12345")[](#l1.32) testcommon("%#+.23X", big, "+0X001234567890ABCDEF12345")[](#l1.33)
testcommon("%#-+.23X", big, "+0X001234567890ABCDEF12345")[](#l1.34)
testcommon("%#-+26.23X", big, "+0X001234567890ABCDEF12345")[](#l1.35)
testcommon("%#-+27.23X", big, "+0X001234567890ABCDEF12345 ")[](#l1.36)
testcommon("%#+27.23X", big, " +0X001234567890ABCDEF12345")[](#l1.37) # next one gets two leading zeroes from precision, and another from the[](#l1.38) # 0 flag and the width[](#l1.39) testcommon("%#+027.23X", big, "+0X0001234567890ABCDEF12345")[](#l1.40)
testcommon("%# 027.23X", big, " 0X0001234567890ABCDEF12345")[](#l1.41) # same, except no 0 flag[](#l1.42) testcommon("%#+27.23X", big, " +0X001234567890ABCDEF12345")[](#l1.43)
testcommon("%#-+27.23x", big, "+0x001234567890abcdef12345 ")[](#l1.44)
testcommon("%#- 27.23x", big, " 0x001234567890abcdef12345 ")[](#l1.45)
+ big = 0o12345670123456701234567012345670 # 32 octal digits testcommon("%o", big, "12345670123456701234567012345670") testcommon("%o", -big, "-12345670123456701234567012345670") @@ -191,13 +200,21 @@ class FormatTest(unittest.TestCase): testcommon("%o", big, "12345670123456701234567012345670") testcommon("%#o", big, "0o12345670123456701234567012345670") testcommon("%#o", -big, "-0o12345670123456701234567012345670")
testcommon("%#38o", big, " 0o12345670123456701234567012345670")[](#l1.54)
testcommon("%#-38o", big, "0o12345670123456701234567012345670 ")[](#l1.55)
testcommon("%#038o", big, "0o000012345670123456701234567012345670")[](#l1.56)
testcommon("%#.34o", big, "0o0012345670123456701234567012345670")[](#l1.57) testcommon("%#.34o", -big, "-0o0012345670123456701234567012345670")[](#l1.58)
testcommon("%#38.34o", big, " 0o0012345670123456701234567012345670")[](#l1.59)
testcommon("%#-38.34o", big, "0o0012345670123456701234567012345670 ")[](#l1.60)
testcommon("%#038.34o", big, "0o000012345670123456701234567012345670")[](#l1.61) testcommon("%#+.34o", big, "+0o0012345670123456701234567012345670")[](#l1.62) testcommon("%# .34o", big, " 0o0012345670123456701234567012345670")[](#l1.63)
testcommon("%#+.34o", big, "+0o0012345670123456701234567012345670")[](#l1.64)
testcommon("%#-+.34o", big, "+0o0012345670123456701234567012345670")[](#l1.65)
testcommon("%#-+37.34o", big, "+0o0012345670123456701234567012345670")[](#l1.66)
testcommon("%#+37.34o", big, "+0o0012345670123456701234567012345670")[](#l1.67)
testcommon("%#+38.34o", big, " +0o0012345670123456701234567012345670")[](#l1.68)
testcommon("%#-+38.34o", big, "+0o0012345670123456701234567012345670 ")[](#l1.69)
testcommon("%#- 38.34o", big, " 0o0012345670123456701234567012345670 ")[](#l1.70)
testcommon("%#+038.34o", big, "+0o00012345670123456701234567012345670")[](#l1.71)
testcommon("%# 038.34o", big, " 0o00012345670123456701234567012345670")[](#l1.72) # next one gets one leading zero from precision[](#l1.73) testcommon("%.33o", big, "012345670123456701234567012345670")[](#l1.74) # base marker added in spite of leading zero (different to Python 2)[](#l1.75)
@@ -208,6 +225,7 @@ class FormatTest(unittest.TestCase): testcommon("%035.33o", big, "00012345670123456701234567012345670") # base marker shouldn't change the size testcommon("%0#35.33o", big, "0o012345670123456701234567012345670") + # Some small ints, in both Python int and flavors). testcommon("%d", 42, "42") testcommon("%d", -42, "-42")
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 3.7.0 alpha 1 Core and Builtins ----------------- +- Issue #29000: Fixed bytes formatting of octals with zero padding in alternate
- Issue #18896: Python function can now have more than 255 parameters. collections.namedtuple() now supports tuples with more than 255 elements.
--- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -974,7 +974,7 @@ PyObject / Write the numeric prefix for "x", "X" and "o" formats if the alternate form is used. For example, write "0x" for the "%#x" format. */
if ((flags & F_ALT) && (c == 'x' || c == 'X')) {[](#l3.7)
if ((flags & F_ALT) && (c == 'o' || c == 'x' || c == 'X')) {[](#l3.8) assert(pbuf[0] == '0');[](#l3.9) assert(pbuf[1] == c);[](#l3.10) if (fill != ' ') {[](#l3.11)
@@ -999,8 +999,7 @@ PyObject * if (fill == ' ') { if (sign) *res++ = sign;
if ((flags & F_ALT) &&[](#l3.16)
(c == 'x' || c == 'X')) {[](#l3.17)
if ((flags & F_ALT) && (c == 'o' || c == 'x' || c == 'X')) {[](#l3.18) assert(pbuf[0] == '0');[](#l3.19) assert(pbuf[1] == c);[](#l3.20) *res++ = *pbuf++;[](#l3.21)