Commit cbda8fc5 authored by Benjamin Peterson's avatar Benjamin Peterson Committed by GitHub

closes bpo-34868: Improve error message with '_' is combined with an invalid...

closes bpo-34868: Improve error message with '_' is combined with an invalid type specifier. (GH-9666)
parent 30534cc7
...@@ -700,6 +700,9 @@ class LongTest(unittest.TestCase): ...@@ -700,6 +700,9 @@ class LongTest(unittest.TestCase):
self.assertRaisesRegex(ValueError, 'Cannot specify both', format, 3, '_,d') self.assertRaisesRegex(ValueError, 'Cannot specify both', format, 3, '_,d')
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 # ensure that only int and float type specifiers work
for format_spec in ([chr(x) for x in range(ord('a'), ord('z')+1)] + 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)]): [chr(x) for x in range(ord('A'), ord('Z')+1)]):
......
...@@ -28,16 +28,17 @@ unknown_presentation_type(Py_UCS4 presentation_type, ...@@ -28,16 +28,17 @@ unknown_presentation_type(Py_UCS4 presentation_type,
} }
static void 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) if (presentation_type > 32 && presentation_type < 128)
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"Cannot specify ',' with '%c'.", "Cannot specify '%c' with '%c'.",
(char)presentation_type); specifier, (char)presentation_type);
else else
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"Cannot specify ',' with '\\x%x'.", "Cannot specify '%c' with '\\x%x'.",
(unsigned int)presentation_type); specifier, (unsigned int)presentation_type);
} }
static void static void
...@@ -117,8 +118,8 @@ is_sign_element(Py_UCS4 c) ...@@ -117,8 +118,8 @@ is_sign_element(Py_UCS4 c)
/* Locale type codes. LT_NO_LOCALE must be zero. */ /* Locale type codes. LT_NO_LOCALE must be zero. */
enum LocaleType { enum LocaleType {
LT_NO_LOCALE = 0, LT_NO_LOCALE = 0,
LT_DEFAULT_LOCALE, LT_DEFAULT_LOCALE = ',',
LT_UNDERSCORE_LOCALE, LT_UNDERSCORE_LOCALE = '_',
LT_UNDER_FOUR_LOCALE, LT_UNDER_FOUR_LOCALE,
LT_CURRENT_LOCALE LT_CURRENT_LOCALE
}; };
...@@ -314,7 +315,7 @@ parse_internal_render_format_spec(PyObject *format_spec, ...@@ -314,7 +315,7 @@ parse_internal_render_format_spec(PyObject *format_spec,
} }
/* fall through */ /* fall through */
default: default:
invalid_comma_type(format->type); invalid_thousands_separator_type(format->thousands_separators, format->type);
return 0; return 0;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment