Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 4 additions & 0 deletions Lib/test/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,10 @@ def test_g_format_has_no_trailing_zeros(self):
self.assertEqual(format(12300050.0, ".6g"), "1.23e+07")
self.assertEqual(format(12300050.0, "#.6g"), "1.23000e+07")

def test_with_two_commas_in_format_specifier(self):
error_msg = "Cannot specify ',' with ','."
with self.assertRaisesRegex(ValueError, error_msg):
'{:,,}'.format(1)

if __name__ == "__main__":
unittest.main()
4 changes: 4 additions & 0 deletions Lib/test/test_fstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,10 @@ def test_invalid_syntax_error_message(self):
with self.assertRaisesRegex(SyntaxError, "f-string: invalid syntax"):
compile("f'{a $ b}'", "?", "exec")

def test_with_two_commas_in_format_specifier(self):
error_msg = "Cannot specify ',' with ','."
with self.assertRaisesRegex(ValueError, error_msg):
f'{1:,,}'

if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixes the wrong error description in the error raised by using 2 `,` in
format string in f-string and :meth:`str.format`.
6 changes: 4 additions & 2 deletions Python/formatter_unicode.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,10 @@ parse_internal_render_format_spec(PyObject *format_spec,
++pos;
}
if (end-pos && READ_spec(pos) == ',') {
invalid_comma_and_underscore();
return 0;
if (format->thousands_separators == LT_UNDERSCORE_LOCALE) {
invalid_comma_and_underscore();
return 0;
}
}

/* Parse field precision */
Expand Down