Skip to content
Snippets Groups Projects
Commit a135bca4 authored by Paul Sokolovsky's avatar Paul Sokolovsky Committed by Damien George
Browse files

py/objstr: format: Return bytes result for bytes format string.

This is an improvement over previous behavior when str was returned for
both str and bytes input format.  This new behaviour is also consistent
with how the % operator works, as well as many other str/bytes methods.

It should be noted that it's not how current versions of CPython work,
where there's a gap in the functionality and bytes.format() is not
supported.
parent 09c5c58a
No related branches found
No related tags found
No related merge requests found
...@@ -1387,7 +1387,7 @@ mp_obj_t mp_obj_str_format(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs ...@@ -1387,7 +1387,7 @@ mp_obj_t mp_obj_str_format(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
GET_STR_DATA_LEN(args[0], str, len); GET_STR_DATA_LEN(args[0], str, len);
int arg_i = 0; int arg_i = 0;
vstr_t vstr = mp_obj_str_format_helper((const char*)str, (const char*)str + len, &arg_i, n_args, args, kwargs); vstr_t vstr = mp_obj_str_format_helper((const char*)str, (const char*)str + len, &arg_i, n_args, args, kwargs);
return mp_obj_new_str_from_vstr(&mp_type_str, &vstr); return mp_obj_new_str_from_vstr(mp_obj_get_type(args[0]), &vstr);
} }
MP_DEFINE_CONST_FUN_OBJ_KW(str_format_obj, 1, mp_obj_str_format); MP_DEFINE_CONST_FUN_OBJ_KW(str_format_obj, 1, mp_obj_str_format);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment