Skip to content
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
3 changes: 3 additions & 0 deletions Lib/test/test_long.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,9 @@ def test__format__(self):
self.assertRaisesRegex(ValueError, 'Cannot specify both', format, 3, '_,d')
self.assertRaisesRegex(ValueError, 'Cannot specify both', format, 3, ',_d')

self.assertRaisesRegex(ValueError, "Cannot specify ',' with 's'", format, 3, ',s')
self.assertRaisesRegex(ValueError, "Cannot specify '_' with 's'", format, 3, '_s')

# ensure that only int and float type specifiers work
for format_spec in ([chr(x) for x in range(ord('a'), ord('z')+1)] +
[chr(x) for x in range(ord('A'), ord('Z')+1)]):
Expand Down
17 changes: 9 additions & 8 deletions Python/formatter_unicode.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ unknown_presentation_type(Py_UCS4 presentation_type,
}

static void
invalid_comma_type(Py_UCS4 presentation_type)
invalid_thousands_separator_type(char specifier, Py_UCS4 presentation_type)
{
assert(specifier == ',' || specifier == '_');
if (presentation_type > 32 && presentation_type < 128)
PyErr_Format(PyExc_ValueError,
"Cannot specify ',' with '%c'.",
(char)presentation_type);
"Cannot specify '%c' with '%c'.",
specifier, (char)presentation_type);
else
PyErr_Format(PyExc_ValueError,
"Cannot specify ',' with '\\x%x'.",
(unsigned int)presentation_type);
"Cannot specify '%c' with '\\x%x'.",
specifier, (unsigned int)presentation_type);
}

static void
Expand Down Expand Up @@ -117,8 +118,8 @@ is_sign_element(Py_UCS4 c)
/* Locale type codes. LT_NO_LOCALE must be zero. */
enum LocaleType {
LT_NO_LOCALE = 0,
LT_DEFAULT_LOCALE,
LT_UNDERSCORE_LOCALE,
LT_DEFAULT_LOCALE = ',',
LT_UNDERSCORE_LOCALE = '_',
LT_UNDER_FOUR_LOCALE,
LT_CURRENT_LOCALE
};
Expand Down Expand Up @@ -314,7 +315,7 @@ parse_internal_render_format_spec(PyObject *format_spec,
}
/* fall through */
default:
invalid_comma_type(format->type);
invalid_thousands_separator_type(format->thousands_separators, format->type);
return 0;
}
}
Expand Down