Commit 7ef75f9f authored by Damien George's avatar Damien George
Browse files

py/objstr: Fix error type for badly formatted format specifier.

Was KeyError, should be ValueError.
parent 51b9a0d0
......@@ -1065,7 +1065,12 @@ mp_obj_t mp_obj_str_format(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwa
type = *s++;
}
if (*s) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_KeyError, "Invalid conversion specification"));
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
terse_str_format_value_error();
} else {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
"invalid format specifier"));
}
}
vstr_free(format_spec);
format_spec = NULL;
......
......@@ -194,3 +194,8 @@ try:
'{0:s}'.format(1)
except ValueError:
print('ValueError')
try:
'{:*"1"}'.format('zz')
except ValueError:
print('ValueError')
Supports Markdown
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