summaryrefslogtreecommitdiffstatshomepage
path: root/py/objstr.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/objstr.c')
-rw-r--r--py/objstr.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/py/objstr.c b/py/objstr.c
index 7765f426d9..fbe61a26f1 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -121,7 +121,7 @@ STATIC void str_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
#else
bool is_bytes = true;
#endif
- if (!MICROPY_PY_BUILTINS_STR_UNICODE && kind == PRINT_STR && !is_bytes) {
+ if (kind == PRINT_RAW || (!MICROPY_PY_BUILTINS_STR_UNICODE && kind == PRINT_STR && !is_bytes)) {
mp_printf(print, "%.*s", str_len, str_data);
} else {
if (is_bytes) {
@@ -1296,6 +1296,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_o
GET_STR_DATA_LEN(pattern, str, len);
const byte *start_str = str;
+ bool is_bytes = MP_OBJ_IS_TYPE(pattern, &mp_type_bytes);
int arg_i = 0;
vstr_t vstr;
mp_print_t print;
@@ -1444,7 +1445,13 @@ not_enough_args:
vstr_t arg_vstr;
mp_print_t arg_print;
vstr_init_print(&arg_vstr, 16, &arg_print);
- mp_obj_print_helper(&arg_print, arg, *str == 'r' ? PRINT_REPR : PRINT_STR);
+ mp_print_kind_t print_kind = (*str == 'r' ? PRINT_REPR : PRINT_STR);
+ if (print_kind == PRINT_STR && is_bytes && MP_OBJ_IS_TYPE(arg, &mp_type_bytes)) {
+ // If we have something like b"%s" % b"1", bytes arg should be
+ // printed undecorated.
+ print_kind = PRINT_RAW;
+ }
+ mp_obj_print_helper(&arg_print, arg, print_kind);
uint vlen = arg_vstr.len;
if (prec < 0) {
prec = vlen;