bpo-35560: Remove assertion from format(float, "n") (GH-11288)

Fix an assertion error in format() in debug build for floating point
formatting with "n" format, zero padding and small width. Release build is
not impacted. Patch by Karthikeyan Singaravelan.
This commit is contained in:
Xtreak 2019-01-07 20:39:14 +05:30 committed by Victor Stinner
parent a0bb51e44c
commit 3f7983a25a
3 changed files with 23 additions and 1 deletions

View File

@ -701,6 +701,25 @@ class FormatTestCase(unittest.TestCase):
self.assertEqual(format(1234.56, '.4'), '1.235e+03')
self.assertEqual(format(12345.6, '.4'), '1.235e+04')
def test_issue35560(self):
self.assertEqual(format(123.0, '00'), '123.0')
self.assertEqual(format(123.34, '00f'), '123.340000')
self.assertEqual(format(123.34, '00e'), '1.233400e+02')
self.assertEqual(format(123.34, '00g'), '123.34')
self.assertEqual(format(123.34, '00.10f'), '123.3400000000')
self.assertEqual(format(123.34, '00.10e'), '1.2334000000e+02')
self.assertEqual(format(123.34, '00.10g'), '123.34')
self.assertEqual(format(123.34, '01f'), '123.340000')
self.assertEqual(format(-123.0, '00'), '-123.0')
self.assertEqual(format(-123.34, '00f'), '-123.340000')
self.assertEqual(format(-123.34, '00e'), '-1.233400e+02')
self.assertEqual(format(-123.34, '00g'), '-123.34')
self.assertEqual(format(-123.34, '00.10f'), '-123.3400000000')
self.assertEqual(format(-123.34, '00.10f'), '-123.3400000000')
self.assertEqual(format(-123.34, '00.10e'), '-1.2334000000e+02')
self.assertEqual(format(-123.34, '00.10g'), '-123.34')
class ReprTestCase(unittest.TestCase):
def test_repr(self):
floats_file = open(os.path.join(os.path.split(__file__)[0],

View File

@ -0,0 +1,3 @@
Fix an assertion error in :func:`format` in debug build for floating point
formatting with "n" format, zero padding and small width. Release build is
not impacted. Patch by Karthikeyan Singaravelan.

View File

@ -9381,6 +9381,7 @@ _PyUnicode_InsertThousandsGrouping(
PyObject *thousands_sep,
Py_UCS4 *maxchar)
{
min_width = Py_MAX(0, min_width);
if (writer) {
assert(digits != NULL);
assert(maxchar == NULL);
@ -9391,7 +9392,6 @@ _PyUnicode_InsertThousandsGrouping(
}
assert(0 <= d_pos);
assert(0 <= n_digits);
assert(0 <= min_width);
assert(grouping != NULL);
if (digits != NULL) {