Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dae5d72

Browse filesBrowse files
bpo-35560: Remove assertion from format(float, "n") (GH-11288) (GH-23231)
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. (cherry picked from commit 3f7983a) Co-authored-by: Xtreak <tir.karthi@gmail.com>
1 parent a63234c commit dae5d72
Copy full SHA for dae5d72

File tree

3 files changed

+23
-1
lines changed
Filter options

3 files changed

+23
-1
lines changed

‎Lib/test/test_float.py

Copy file name to clipboardExpand all lines: Lib/test/test_float.py
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,25 @@ def test_issue5864(self):
697697
self.assertEqual(format(1234.56, '.4'), '1.235e+03')
698698
self.assertEqual(format(12345.6, '.4'), '1.235e+04')
699699

700+
def test_issue35560(self):
701+
self.assertEqual(format(123.0, '00'), '123.0')
702+
self.assertEqual(format(123.34, '00f'), '123.340000')
703+
self.assertEqual(format(123.34, '00e'), '1.233400e+02')
704+
self.assertEqual(format(123.34, '00g'), '123.34')
705+
self.assertEqual(format(123.34, '00.10f'), '123.3400000000')
706+
self.assertEqual(format(123.34, '00.10e'), '1.2334000000e+02')
707+
self.assertEqual(format(123.34, '00.10g'), '123.34')
708+
self.assertEqual(format(123.34, '01f'), '123.340000')
709+
710+
self.assertEqual(format(-123.0, '00'), '-123.0')
711+
self.assertEqual(format(-123.34, '00f'), '-123.340000')
712+
self.assertEqual(format(-123.34, '00e'), '-1.233400e+02')
713+
self.assertEqual(format(-123.34, '00g'), '-123.34')
714+
self.assertEqual(format(-123.34, '00.10f'), '-123.3400000000')
715+
self.assertEqual(format(-123.34, '00.10f'), '-123.3400000000')
716+
self.assertEqual(format(-123.34, '00.10e'), '-1.2334000000e+02')
717+
self.assertEqual(format(-123.34, '00.10g'), '-123.34')
718+
700719
class ReprTestCase(unittest.TestCase):
701720
def test_repr(self):
702721
floats_file = open(os.path.join(os.path.split(__file__)[0],
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix an assertion error in :func:`format` in debug build for floating point
2+
formatting with "n" format, zero padding and small width. Release build is
3+
not impacted. Patch by Karthikeyan Singaravelan.

‎Objects/unicodeobject.c

Copy file name to clipboardExpand all lines: Objects/unicodeobject.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9473,6 +9473,7 @@ _PyUnicode_InsertThousandsGrouping(
94739473
PyObject *thousands_sep,
94749474
Py_UCS4 *maxchar)
94759475
{
9476+
min_width = Py_MAX(0, min_width);
94769477
if (writer) {
94779478
assert(digits != NULL);
94789479
assert(maxchar == NULL);
@@ -9483,7 +9484,6 @@ _PyUnicode_InsertThousandsGrouping(
94839484
}
94849485
assert(0 <= d_pos);
94859486
assert(0 <= n_digits);
9486-
assert(0 <= min_width);
94879487
assert(grouping != NULL);
94889488

94899489
if (digits != NULL) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.