Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[3.6] bpo-35560: Remove assertion from format(float, "n") (GH-11288) #23231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Lib/test/test_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,25 @@ def test_issue5864(self):
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],
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -9473,6 +9473,7 @@ _PyUnicode_InsertThousandsGrouping(
PyObject *thousands_sep,
Py_UCS4 *maxchar)
{
min_width = Py_MAX(0, min_width);
if (writer) {
assert(digits != NULL);
assert(maxchar == NULL);
Expand All @@ -9483,7 +9484,6 @@ _PyUnicode_InsertThousandsGrouping(
}
assert(0 <= d_pos);
assert(0 <= n_digits);
assert(0 <= min_width);
assert(grouping != NULL);

if (digits != NULL) {
Expand Down