Skip to content

Commit d4df8f4

Browse files
committed
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.
1 parent 824f83f commit d4df8f4

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

py/objstr.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
12591259
}
12601260

12611261
switch (type) {
1262-
case '\0':
1263-
mp_obj_print_helper(&print, arg, PRINT_STR);
1264-
break;
1265-
1262+
case '\0': // no explicit format type implies 's'
12661263
case 's': {
12671264
mp_uint_t slen;
12681265
const char *s = mp_obj_str_get_data(arg, &slen);

tests/basics/string_format.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ def test(fmt, *args):
6262
test("{:@=6d}", -123)
6363
test("{:06d}", -123)
6464

65+
test("{:>20}", "foo")
66+
test("{:^20}", "foo")
67+
test("{:<20}", "foo")
68+
6569
print("{foo}/foo".format(foo="bar"))
6670
print("{}".format(123, foo="bar"))
6771
print("{}-{foo}".format(123, foo="bar"))

0 commit comments

Comments
 (0)