8000 py/modbuiltins: Make oct/hex work when !MICROPY_PY_BUILTINS_STR_OP_MO… · andrewleech/micropython@93f2997 · GitHub
[go: up one dir, main page]

Skip to content

Commit 93f2997

Browse files
pfalcondpgeorge
authored andcommitted
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.
1 parent 2da5d41 commit 93f2997

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

py/modbuiltins.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,12 @@ STATIC mp_obj_t mp_builtin_hash(mp_obj_t o_in) {
217217
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_hash_obj, mp_builtin_hash);
218218

219219
STATIC mp_obj_t mp_builtin_hex(mp_obj_t o_in) {
220+
#if MICROPY_PY_BUILTINS_STR_OP_MODULO
220221
return mp_binary_op(MP_BINARY_OP_MODULO, MP_OBJ_NEW_QSTR(MP_QSTR__percent__hash_x), o_in);
222+
#else
223+
mp_obj_t args[] = { MP_OBJ_NEW_QSTR(MP_QSTR__brace_open__colon__hash_x_brace_close_), o_in };
224+
return mp_obj_str_format(MP_ARRAY_SIZE(args), args, NULL);
225+
#endif
221226
}
222227
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_hex_obj, mp_builtin_hex);
223228

@@ -322,7 +327,12 @@ STATIC mp_obj_t mp_builtin_next(mp_obj_t o) {
322327
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_next_obj, mp_builtin_next);
323328

324329
STATIC mp_obj_t mp_builtin_oct(mp_obj_t o_in) {
330+
#if MICROPY_PY_BUILTINS_STR_OP_MODULO
325331
return mp_binary_op(MP_BINARY_OP_MODULO, MP_OBJ_NEW_QSTR(MP_QSTR__percent__hash_o), o_in);
332+
#else
333+
mp_obj_t args[] = { MP_OBJ_NEW_QSTR(MP_QSTR__brace_open__colon__hash_o_brace_close_), o_in };
334+
return mp_obj_str_format(MP_ARRAY_SIZE(args), args, NULL);
335+
#endif
326336
}
327337
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_oct_obj, mp_builtin_oct);
328338

py/qstrdefs.h

Lines changed: 5 additions & 0 deletions
4163
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ Q()
3737
Q(*)
3838
Q(_)
3939
Q(/)
40+
#if MICROPY_PY_BUILTINS_STR_OP_MODULO
4041
Q(%#o)
4142
Q(%#x)
43+
#else
44+
Q({:#o})
45+
Q({:#x})
46+
#endif
4247
Q({:#b})
4348
Q( )
4449
Q(\n)

0 commit comments

Comments
 (0)
0