py/modbuiltins: Make oct/hex work when !MICROPY_PY_BUILTINS_STR_OP_MODULO
Instead of redirecting to str.__mod__(), use str.format() in this case.
This commit is contained in:
parent
2da5d41350
commit
93f29975db
@ -217,7 +217,12 @@ STATIC mp_obj_t mp_builtin_hash(mp_obj_t o_in) {
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_hash_obj, mp_builtin_hash);
|
||||
|
||||
STATIC mp_obj_t mp_builtin_hex(mp_obj_t o_in) {
|
||||
#if MICROPY_PY_BUILTINS_STR_OP_MODULO
|
||||
return mp_binary_op(MP_BINARY_OP_MODULO, MP_OBJ_NEW_QSTR(MP_QSTR__percent__hash_x), o_in);
|
||||
#else
|
||||
mp_obj_t args[] = { MP_OBJ_NEW_QSTR(MP_QSTR__brace_open__colon__hash_x_brace_close_), o_in };
|
||||
return mp_obj_str_format(MP_ARRAY_SIZE(args), args, NULL);
|
||||
#endif
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_hex_obj, mp_builtin_hex);
|
||||
|
||||
@ -322,7 +327,12 @@ STATIC mp_obj_t mp_builtin_next(mp_obj_t o) {
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_next_obj, mp_builtin_next);
|
||||
|
||||
STATIC mp_obj_t mp_builtin_oct(mp_obj_t o_in) {
|
||||
#if MICROPY_PY_BUILTINS_STR_OP_MODULO
|
||||
return mp_binary_op(MP_BINARY_OP_MODULO, MP_OBJ_NEW_QSTR(MP_QSTR__percent__hash_o), o_in);
|
||||
#else
|
||||
mp_obj_t args[] = { MP_OBJ_NEW_QSTR(MP_QSTR__brace_open__colon__hash_o_brace_close_), o_in };
|
||||
return mp_obj_str_format(MP_ARRAY_SIZE(args), args, NULL);
|
||||
#endif
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_oct_obj, mp_builtin_oct);
|
||||
|
||||
|
@ -37,8 +37,13 @@ Q()
|
||||
Q(*)
|
||||
Q(_)
|
||||
Q(/)
|
||||
#if MICROPY_PY_BUILTINS_STR_OP_MODULO
|
||||
Q(%#o)
|
||||
Q(%#x)
|
||||
#else
|
||||
Q({:#o})
|
||||
Q({:#x})
|
||||
#endif
|
||||
Q({:#b})
|
||||
Q( )
|
||||
Q(\n)
|
||||
|
Loading…
Reference in New Issue
Block a user