py/objstr: In format error message, use common string with %s for type.

This error message did not consume all of its variable args, a bug
introduced long ago in baf6f14deb.  By fixing
it to use %s (instead of keeping the string as-is and deleting the last
arg) the same error message string is now reused three times in this format
function and gives a code size reduction of around 130 bytes.  It also now
gives a better error message when a non-string is passed in as an argument
to format, eg '{:d}'.format([]).
This commit is contained in:
Damien George 2018-07-30 12:46:47 +10:00
parent 571295d090
commit aec6fa9160
1 changed files with 2 additions and 2 deletions

View File

@ -1327,7 +1327,7 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
terse_str_format_value_error();
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"unknown format code '%c' for object of type 'float'",
"unknown format code '%c' for object of type '%s'",
type, mp_obj_get_type_str(arg)));
}
}
@ -1363,7 +1363,7 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
terse_str_format_value_error();
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"unknown format code '%c' for object of type 'str'",
"unknown format code '%c' for object of type '%s'",
type, mp_obj_get_type_str(arg)));
}
}