kopia lustrzana https://github.com/micropython/micropython
py/objstr: In str.format, handle case of no format spec for string arg.
Handles, eg, "{:>20}".format("foo"), where there is no explicit spec for the type of the argument.pull/1749/merge
rodzic
824f83fd20
commit
d4df8f4925
|
@ -1259,10 +1259,7 @@ mp_obj_t mp_obj_str_format(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwa
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case '\0':
|
case '\0': // no explicit format type implies 's'
|
||||||
mp_obj_print_helper(&print, arg, PRINT_STR);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 's': {
|
case 's': {
|
||||||
mp_uint_t slen;
|
mp_uint_t slen;
|
||||||
const char *s = mp_obj_str_get_data(arg, &slen);
|
const char *s = mp_obj_str_get_data(arg, &slen);
|
||||||
|
|
|
@ -62,6 +62,10 @@ test("{:@<6d}", -123)
|
||||||
test("{:@=6d}", -123)
|
test("{:@=6d}", -123)
|
||||||
test("{:06d}", -123)
|
test("{:06d}", -123)
|
||||||
|
|
||||||
|
test("{:>20}", "foo")
|
||||||
|
test("{:^20}", "foo")
|
||||||
|
test("{:<20}", "foo")
|
||||||
|
|
||||||
print("{foo}/foo".format(foo="bar"))
|
print("{foo}/foo".format(foo="bar"))
|
||||||
print("{}".format(123, foo="bar"))
|
print("{}".format(123, foo="bar"))
|
||||||
print("{}-{foo}".format(123, foo="bar"))
|
print("{}-{foo}".format(123, foo="bar"))
|
||||||
|
|
Ładowanie…
Reference in New Issue