diff options
author | mcskatkat <mc_skatkat@hotmail.com> | 2023-07-11 00:50:33 +0300 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2023-09-01 14:31:57 +1000 |
commit | e0a148060025a75f4051e5009d9dc3728cb2bc75 (patch) | |
tree | 3fc1045f4bcea605af3ec862bc0378fcc51966d2 /py/objstr.c | |
parent | 83f2f36b9e5fea90a947aada5e1c8065468c0e70 (diff) |
py/objstr: Fix `str % {}` edge case.
Eliminate `TypeError` when format string contains no named conversions.
This matches CPython behavior.
Signed-off-by: mcskatkat <mc_skatkat@hotmail.com>
Diffstat (limited to 'py/objstr.c')
-rw-r--r-- | py/objstr.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/py/objstr.c b/py/objstr.c index b966a7016..5dfe94ac4 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -1645,7 +1645,9 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_ } } - if (arg_i != n_args) { + if (dict == MP_OBJ_NULL && arg_i != n_args) { + // NOTE: if `dict` exists, then `n_args` is 1 and the dict is always consumed; either + // positionally, or as a map of named args, even if none were actually referenced. mp_raise_TypeError(MP_ERROR_TEXT("format string didn't convert all arguments")); } |