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

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
address review: disallow precision for 'c' type
  • Loading branch information
skirpichev committed Apr 2, 2025
commit d6aa05ffedd3dcb639ad83de4d255fe713601a87
1 change: 1 addition & 0 deletions Lib/test/test_long.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@ def test__format__(self):
self.assertRaises(ValueError, format, -129, '.8b')

# make sure these are errors
self.assertRaises(ValueError, format, 3, "1.3c") # precision disallowed with 'c',
self.assertRaises(ValueError, format, 3, "_c") # underscore,
self.assertRaises(ValueError, format, 3, ",c") # comma, and
self.assertRaises(ValueError, format, 3, "+c") # sign not allowed
Expand Down
7 changes: 7 additions & 0 deletions Python/formatter_unicode.c
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,13 @@ format_long_internal(PyObject *value, const InternalFormatSpec *format,
from a hard-code pseudo-locale */
LocaleInfo locale = LocaleInfo_STATIC_INIT;

/* no precision allowed on 'c' integer representation type */
if (format->precision != -1 && format->type == 'c') {
PyErr_SetString(PyExc_ValueError,
"Precision not allowed with 'c' integer format specifier");
goto done;
}

/* no negative zero coercion on integers */
if (format->no_neg_0) {
PyErr_SetString(PyExc_ValueError,
Expand Down
Loading