py: Add %q format support to mp_[v]printf, and use it.
This commit is contained in:
@@ -56,13 +56,13 @@ STATIC mp_uint_t namedtuple_find_field(mp_obj_namedtuple_type_t *type, qstr name
|
||||
STATIC void namedtuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) {
|
||||
(void)kind;
|
||||
mp_obj_namedtuple_t *o = o_in;
|
||||
mp_printf(print, "%s(", qstr_str(o->tuple.base.type->name));
|
||||
mp_printf(print, "%q(", o->tuple.base.type->name);
|
||||
const qstr *fields = ((mp_obj_namedtuple_type_t*)o->tuple.base.type)->fields;
|
||||
for (mp_uint_t i = 0; i < o->tuple.len; i++) {
|
||||
if (i > 0) {
|
||||
mp_print_str(print, ", ");
|
||||
}
|
||||
mp_printf(print, "%s=", qstr_str(fields[i]));
|
||||
mp_printf(print, "%q=", fields[i]);
|
||||
mp_obj_print_helper(print, o->tuple.items[i], PRINT_REPR);
|
||||
}
|
||||
mp_print_str(print, ")");
|
||||
@@ -96,8 +96,8 @@ STATIC mp_obj_t namedtuple_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_
|
||||
num_fields, n_args + n_kw));
|
||||
} else if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED) {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
"%s() takes %d positional arguments but %d were given",
|
||||
qstr_str(type->base.name), num_fields, n_args + n_kw));
|
||||
"%q() takes %d positional arguments but %d were given",
|
||||
type->base.name, num_fields, n_args + n_kw));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,8 +121,7 @@ STATIC mp_obj_t namedtuple_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_
|
||||
mp_arg_error_terse_mismatch();
|
||||
} else {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
"unexpected keyword argument '%s'",
|
||||
qstr_str(kw)));
|
||||
"unexpected keyword argument '%q'", kw));
|
||||
}
|
||||
}
|
||||
if (arg_objects[id] != NULL) {
|
||||
@@ -130,8 +129,7 @@ STATIC mp_obj_t namedtuple_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_
|
||||
mp_arg_error_terse_mismatch();
|
||||
} else {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
"function got multiple values for argument '%s'",
|
||||
qstr_str(kw)));
|
||||
"function got multiple values for argument '%q'", kw));
|
||||
}
|
||||
}
|
||||
arg_objects[id] = args[i + 1];
|
||||
|
||||
Reference in New Issue
Block a user