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:
Paul Sokolovsky 2018-09-16 07:23:53 +03:00 committed by Damien George
parent 2da5d41350
commit 93f29975db
2 changed files with 15 additions and 0 deletions

View File

@ -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); 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) { 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); 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); 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); 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) { 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); 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); MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_oct_obj, mp_builtin_oct);

View File

@ -37,8 +37,13 @@ Q()
Q(*) Q(*)
Q(_) Q(_)
Q(/) Q(/)
#if MICROPY_PY_BUILTINS_STR_OP_MODULO
Q(%#o) Q(%#o)
Q(%#x) Q(%#x)
#else
Q({:#o})
Q({:#x})
#endif
Q({:#b}) Q({:#b})
Q( ) Q( )
Q(\n) Q(\n)