summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--py/objstr.c7
-rw-r--r--tests/basics/string_format.py5
2 files changed, 11 insertions, 1 deletions
diff --git a/py/objstr.c b/py/objstr.c
index b51636a6ca..98360d9e11 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -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;
diff --git a/tests/basics/string_format.py b/tests/basics/string_format.py
index d0518243cf..55d843e1e1 100644
--- a/tests/basics/string_format.py
+++ b/tests/basics/string_format.py
@@ -194,3 +194,8 @@ try:
'{0:s}'.format(1)
except ValueError:
print('ValueError')
+
+try:
+ '{:*"1"}'.format('zz')
+except ValueError:
+ print('ValueError')