py: Use preprocessor to detect error reporting level (terse/detailed).

Instead of compiler-level if-logic.  This is necessary to know what error
strings are included in the build at the preprocessor stage, so that string
compression can be implemented.
This commit is contained in:
Jim Mussared 2019-09-26 22:52:04 +10:00 committed by Damien George
parent 312c699491
commit a9a745e4b4
11 changed files with 384 additions and 380 deletions

View File

@ -38,40 +38,40 @@ void mp_arg_check_num_sig(size_t n_args, size_t n_kw, uint32_t sig) {
size_t n_args_max = (sig >> 1) & 0xffff;
if (n_kw && !takes_kw) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_arg_error_terse_mismatch();
} else {
mp_raise_TypeError("function doesn't take keyword arguments");
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_arg_error_terse_mismatch();
#else
mp_raise_TypeError("function doesn't take keyword arguments");
#endif
}
if (n_args_min == n_args_max) {
if (n_args != n_args_min) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_arg_error_terse_mismatch();
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"function takes %d positional arguments but %d were given",
n_args_min, n_args);
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_arg_error_terse_mismatch();
#else
mp_raise_msg_varg(&mp_type_TypeError,
"function takes %d positional arguments but %d were given",
n_args_min, n_args);
#endif
}
} else {
if (n_args < n_args_min) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_arg_error_terse_mismatch();
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"function missing %d required positional arguments",
n_args_min - n_args);
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_arg_error_terse_mismatch();
#else
mp_raise_msg_varg(&mp_type_TypeError,
"function missing %d required positional arguments",
n_args_min - n_args);
#endif
} else if (n_args > n_args_max) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_arg_error_terse_mismatch();
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"function expected at most %d arguments, got %d",
n_args_max, n_args);
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_arg_error_terse_mismatch();
#else
mp_raise_msg_varg(&mp_type_TypeError,
"function expected at most %d arguments, got %d",
n_args_max, n_args);
#endif
}
}
}
@ -90,11 +90,11 @@ void mp_arg_parse_all(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n
mp_map_elem_t *kw = mp_map_lookup(kws, MP_OBJ_NEW_QSTR(allowed[i].qst), MP_MAP_LOOKUP);
if (kw == NULL) {
if (allowed[i].flags & MP_ARG_REQUIRED) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_arg_error_terse_mismatch();
} else {
mp_raise_msg_varg(&mp_type_TypeError, "'%q' argument required", allowed[i].qst);
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_arg_error_terse_mismatch();
#else
mp_raise_msg_varg(&mp_type_TypeError, "'%q' argument required", allowed[i].qst);
#endif
}
out_vals[i] = allowed[i].defval;
continue;
@ -114,20 +114,20 @@ void mp_arg_parse_all(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n
}
if (pos_found < n_pos) {
extra_positional:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_arg_error_terse_mismatch();
} else {
// TODO better error message
mp_raise_TypeError("extra positional arguments given");
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_arg_error_terse_mismatch();
#else
// TODO better error message
mp_raise_TypeError("extra positional arguments given");
#endif
}
if (kws_found < kws->used) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_arg_error_terse_mismatch();
} else {
// TODO better error message
mp_raise_TypeError("extra keyword arguments given");
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_arg_error_terse_mismatch();
#else
// TODO better error message
mp_raise_TypeError("extra keyword arguments given");
#endif
}
}

12
py/bc.c
View File

@ -212,12 +212,12 @@ void mp_setup_code_state(mp_code_state_t *code_state, size_t n_args, size_t n_kw
}
// Didn't find name match with positional args
if ((scope_flags & MP_SCOPE_FLAG_VARKEYWORDS) == 0) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("unexpected keyword argument");
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"unexpected keyword argument '%q'", MP_OBJ_QSTR_VALUE(wanted_arg_name));
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("unexpected keyword argument");
#else
mp_raise_msg_varg(&mp_type_TypeError,
"unexpected keyword argument '%q'", MP_OBJ_QSTR_VALUE(wanted_arg_name));
#endif
}
mp_obj_dict_store(dict, kwargs[2 * i], kwargs[2 * i + 1]);
continue2:;

View File

@ -396,11 +396,11 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
#endif
if (module_obj == MP_OBJ_NULL) {
// couldn't find the file, so fail
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_ImportError, "module not found");
} else {
mp_raise_msg_varg(&mp_type_ImportError, "no module named '%q'", mod_name);
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_msg(&mp_type_ImportError, "module not found");
#else
mp_raise_msg_varg(&mp_type_ImportError, "no module named '%q'", mod_name);
#endif
}
} else {
// found the file, so get the module
@ -499,11 +499,11 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
#endif
// Couldn't find the module, so fail
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_ImportError, "module not found");
} else {
mp_raise_msg_varg(&mp_type_ImportError, "no module named '%q'", module_name_qstr);
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_msg(&mp_type_ImportError, "module not found");
#else
mp_raise_msg_varg(&mp_type_ImportError, "no module named '%q'", module_name_qstr);
#endif
}
#endif // MICROPY_ENABLE_EXTERNAL_IMPORT

View File

@ -2552,21 +2552,21 @@ STATIC void compile_atom_brace_helper(compiler_t *comp, mp_parse_node_struct_t *
compile_node(comp, pn_i);
if (is_dict) {
if (!is_key_value) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
compile_syntax_error(comp, (mp_parse_node_t)pns, "invalid syntax");
} else {
compile_syntax_error(comp, (mp_parse_node_t)pns, "expecting key:value for dict");
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
compile_syntax_error(comp, (mp_parse_node_t)pns, "invalid syntax");
#else
compile_syntax_error(comp, (mp_parse_node_t)pns, "expecting key:value for dict");
#endif
return;
}
EMIT(store_map);
} else {
if (is_key_value) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
compile_syntax_error(comp, (mp_parse_node_t)pns, "invalid syntax");
} else {
compile_syntax_error(comp, (mp_parse_node_t)pns, "expecting just a value for set");
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
compile_syntax_error(comp, (mp_parse_node_t)pns, "invalid syntax");
#else
compile_syntax_error(comp, (mp_parse_node_t)pns, "expecting just a value for set");
#endif
return;
}
}

View File

@ -372,12 +372,12 @@ STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) {
}
}
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("ord expects a character");
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"ord() expected a character, but string of length %d found", (int)len);
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("ord expects a character");
#else
mp_raise_msg_varg(&mp_type_TypeError,
"ord() expected a character, but string of length %d found", (int)len);
#endif
}
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_ord_obj, mp_builtin_ord);

120
py/obj.c
View File

@ -359,12 +359,12 @@ mp_float_t mp_obj_get_float(mp_obj_t arg) {
mp_float_t val;
if (!mp_obj_get_float_maybe(arg, &val)) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("can't convert to float");
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"can't convert %s to float", mp_obj_get_type_str(arg));
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("can't convert to float");
#else
mp_raise_msg_varg(&mp_type_TypeError,
"can't convert %s to float", mp_obj_get_type_str(arg));
#endif
}
return val;
@ -392,12 +392,12 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
} else if (mp_obj_is_type(arg, &mp_type_complex)) {
mp_obj_complex_get(arg, real, imag);
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("can't convert to complex");
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"can't convert %s to complex", mp_obj_get_type_str(arg));
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("can't convert to complex");
#else
mp_raise_msg_varg(&mp_type_TypeError,
"can't convert %s to complex", mp_obj_get_type_str(arg));
#endif
}
}
#endif
@ -410,12 +410,12 @@ void mp_obj_get_array(mp_obj_t o, size_t *len, mp_obj_t **items) {
} else if (mp_obj_is_type(o, &mp_type_list)) {
mp_obj_list_get(o, len, items);
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("expected tuple/list");
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"object '%s' isn't a tuple or list", mp_obj_get_type_str(o));
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("expected tuple/list");
#else
mp_raise_msg_varg(&mp_type_TypeError,
"object '%s' isn't a tuple or list", mp_obj_get_type_str(o));
#endif
}
}
@ -424,12 +424,12 @@ void mp_obj_get_array_fixed_n(mp_obj_t o, size_t len, mp_obj_t **items) {
size_t seq_len;
mp_obj_get_array(o, &seq_len, items);
if (seq_len != len) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_ValueError("tuple/list has wrong length");
} else {
mp_raise_msg_varg(&mp_type_ValueError,
"requested length %d but object has length %d", (int)len, (int)seq_len);
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_ValueError("tuple/list has wrong length");
#else
mp_raise_msg_varg(&mp_type_ValueError,
"requested length %d but object has length %d", (int)len, (int)seq_len);
#endif
}
}
@ -439,13 +439,13 @@ size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool
if (mp_obj_is_small_int(index)) {
i = MP_OBJ_SMALL_INT_VALUE(index);
} else if (!mp_obj_get_int_maybe(index, &i)) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("indices must be integers");
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"%q indices must be integers, not %s",
type->name, mp_obj_get_type_str(index));
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("indices must be integers");
#else
mp_raise_msg_varg(&mp_type_TypeError,
"%q indices must be integers, not %s",
type->name, mp_obj_get_type_str(index));
#endif
}
if (i < 0) {
@ -459,11 +459,11 @@ size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool
}
} else {
if (i < 0 || (mp_uint_t)i >= len) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_IndexError, "index out of range");
} else {
mp_raise_msg_varg(&mp_type_IndexError, "%q index out of range", type->name);
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_msg(&mp_type_IndexError, "index out of range");
#else
mp_raise_msg_varg(&mp_type_IndexError, "%q index out of range", type->name);
#endif
}
}
@ -493,12 +493,12 @@ mp_obj_t mp_obj_id(mp_obj_t o_in) {
mp_obj_t mp_obj_len(mp_obj_t o_in) {
mp_obj_t len = mp_obj_len_maybe(o_in);
if (len == MP_OBJ_NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("object has no len");
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"object of type '%s' has no len()", mp_obj_get_type_str(o_in));
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("object has no len");
#else
mp_raise_msg_varg(&mp_type_TypeError,
"object of type '%s' has no len()", mp_obj_get_type_str(o_in));
#endif
} else {
return len;
}
@ -534,26 +534,26 @@ mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
// TODO: call base classes here?
}
if (value == MP_OBJ_NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("object doesn't support item deletion");
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"'%s' object doesn't support item deletion", mp_obj_get_type_str(base));
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("object doesn't support item deletion");
#else
mp_raise_msg_varg(&mp_type_TypeError,
"'%s' object doesn't support item deletion", mp_obj_get_type_str(base));
#endif
} else if (value == MP_OBJ_SENTINEL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("object isn't subscriptable");
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"'%s' object isn't subscriptable", mp_obj_get_type_str(base));
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("object isn't subscriptable");
#else
mp_raise_msg_varg(&mp_type_TypeError,
"'%s' object isn't subscriptable", mp_obj_get_type_str(base));
#endif
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("object doesn't support item assignment");
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"'%s' object doesn't support item assignment", mp_obj_get_type_str(base));
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("object doesn't support item assignment");
#else
mp_raise_msg_varg(&mp_type_TypeError,
"'%s' object doesn't support item assignment", mp_obj_get_type_str(base));
#endif
}
}

View File

@ -95,17 +95,17 @@ STATIC mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args,
const mp_obj_namedtuple_type_t *type = (const mp_obj_namedtuple_type_t *)type_in;
size_t num_fields = type->n_fields;
if (n_args + n_kw != num_fields) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_arg_error_terse_mismatch();
} else if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL) {
mp_raise_msg_varg(&mp_type_TypeError,
"function takes %d positional arguments but %d were given",
num_fields, n_args + n_kw);
} else if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED) {
mp_raise_msg_varg(&mp_type_TypeError,
"%q() takes %d positional arguments but %d were given",
type->base.name, num_fields, n_args + n_kw);
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_arg_error_terse_mismatch();
#elif MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL
mp_raise_msg_varg(&mp_type_TypeError,
"function takes %d positional arguments but %d were given",
num_fields, n_args + n_kw);
#elif MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
mp_raise_msg_varg(&mp_type_TypeError,
"%q() takes %d positional arguments but %d were given",
type->base.name, num_fields, n_args + n_kw);
#endif
}
// Create a tuple and set the type to this namedtuple
@ -121,19 +121,19 @@ STATIC mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args,
qstr kw = mp_obj_str_get_qstr(args[i]);
size_t id = mp_obj_namedtuple_find_field(type, kw);
if (id == (size_t)-1) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_arg_error_terse_mismatch();
} else {
mp_raise_msg_varg(&mp_type_TypeError, "unexpected keyword argument '%q'", kw);
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_arg_error_terse_mismatch();
#else
mp_raise_msg_varg(&mp_type_TypeError, "unexpected keyword argument '%q'", kw);
#endif
}
if (tuple->items[id] != MP_OBJ_NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_arg_error_terse_mismatch();
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"function got multiple values for argument '%q'", kw);
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_arg_error_terse_mismatch();
#else
mp_raise_msg_varg(&mp_type_TypeError,
"function got multiple values for argument '%q'", kw);
#endif
}
tuple->items[id] = args[i + 1];
}

View File

@ -959,11 +959,11 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
vstr_add_byte(&vstr, '}');
continue;
}
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
terse_str_format_value_error();
} else {
mp_raise_ValueError("single '}' encountered in format string");
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
#else
mp_raise_ValueError("single '}' encountered in format string");
#endif
}
if (*str != '{') {
vstr_add_byte(&vstr, *str);
@ -998,19 +998,19 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
if (str < top && (*str == 'r' || *str == 's')) {
conversion = *str++;
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
terse_str_format_value_error();
} else if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL) {
mp_raise_ValueError("bad conversion specifier");
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
#elif MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL
mp_raise_ValueError("bad conversion specifier");
#else
if (str >= top) {
mp_raise_ValueError(
"end of format while looking for conversion specifier");
} else {
if (str >= top) {
mp_raise_ValueError(
"end of format while looking for conversion specifier");
} else {
mp_raise_msg_varg(&mp_type_ValueError,
"unknown conversion specifier %c", *str);
}
mp_raise_msg_varg(&mp_type_ValueError,
"unknown conversion specifier %c", *str);
}
#endif
}
}
@ -1036,18 +1036,18 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
}
}
if (str >= top) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
terse_str_format_value_error();
} else {
mp_raise_ValueError("unmatched '{' in format");
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
#else
mp_raise_ValueError("unmatched '{' in format");
#endif
}
if (*str != '}') {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
terse_str_format_value_error();
} else {
mp_raise_ValueError("expected ':' after format specifier");
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
#else
mp_raise_ValueError("expected ':' after format specifier");
#endif
}
mp_obj_t arg = mp_const_none;
@ -1056,12 +1056,12 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
int index = 0;
if (MP_LIKELY(unichar_isdigit(*field_name))) {
if (*arg_i > 0) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
terse_str_format_value_error();
} else {
mp_raise_ValueError(
"can't switch from automatic field numbering to manual field specification");
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
#else
mp_raise_ValueError(
"can't switch from automatic field numbering to manual field specification");
#endif
}
field_name = str_to_int(field_name, field_name_top, &index);
if ((uint)index >= n_args - 1) {
@ -1086,12 +1086,12 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
}
} else {
if (*arg_i < 0) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
terse_str_format_value_error();
} else {
mp_raise_ValueError(
"can't switch from manual field specification to automatic field numbering");
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
#else
mp_raise_ValueError(
"can't switch from manual field specification to automatic field numbering");
#endif
}
if ((uint)*arg_i >= n_args - 1) {
mp_raise_msg(&mp_type_IndexError, "tuple index out of range");
@ -1179,11 +1179,11 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
type = *s++;
}
if (*s) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
terse_str_format_value_error();
} else {
mp_raise_ValueError("invalid format specifier");
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
#else
mp_raise_ValueError("invalid format specifier");
#endif
}
vstr_clear(&format_spec_vstr);
}
@ -1200,19 +1200,19 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
if (flags & (PF_FLAG_SHOW_SIGN | PF_FLAG_SPACE_SIGN)) {
if (type == 's') {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
terse_str_format_value_error();
} else {
mp_raise_ValueError("sign not allowed in string format specifier");
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
#else
mp_raise_ValueError("sign not allowed in string format specifier");
#endif
}
if (type == 'c') {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
terse_str_format_value_error();
} else {
mp_raise_ValueError(
"sign not allowed with integer format specifier 'c'");
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
#else
mp_raise_ValueError(
"sign not allowed with integer format specifier 'c'");
#endif
}
}
@ -1271,13 +1271,13 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
break;
default:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
terse_str_format_value_error();
} else {
mp_raise_msg_varg(&mp_type_ValueError,
"unknown format code '%c' for object of type '%s'",
type, mp_obj_get_type_str(arg));
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
#else
mp_raise_msg_varg(&mp_type_ValueError,
"unknown format code '%c' for object of type '%s'",
type, mp_obj_get_type_str(arg));
#endif
}
}
@ -1343,24 +1343,24 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
#endif
default:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
terse_str_format_value_error();
} else {
mp_raise_msg_varg(&mp_type_ValueError,
"unknown format code '%c' for object of type '%s'",
type, mp_obj_get_type_str(arg));
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
#else
mp_raise_msg_varg(&mp_type_ValueError,
"unknown format code '%c' for object of type '%s'",
type, mp_obj_get_type_str(arg));
#endif
}
} else {
// arg doesn't look like a number
if (align == '=') {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
terse_str_format_value_error();
} else {
mp_raise_ValueError(
"'=' alignment not allowed in string format specifier");
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
#else
mp_raise_ValueError(
"'=' alignment not allowed in string format specifier");
#endif
}
switch (type) {
@ -1379,13 +1379,13 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
}
default:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
terse_str_format_value_error();
} else {
mp_raise_msg_varg(&mp_type_ValueError,
"unknown format code '%c' for object of type '%s'",
type, mp_obj_get_type_str(arg));
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
#else
mp_raise_msg_varg(&mp_type_ValueError,
"unknown format code '%c' for object of type '%s'",
type, mp_obj_get_type_str(arg));
#endif
}
}
}
@ -1408,7 +1408,9 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_
mp_check_self(mp_obj_is_str_or_bytes(pattern));
GET_STR_DATA_LEN(pattern, str, len);
#if MICROPY_ERROR_REPORTING != MICROPY_ERROR_REPORTING_TERSE
const byte *start_str = str;
#endif
bool is_bytes = mp_obj_is_type(pattern, &mp_type_bytes);
size_t arg_i = 0;
vstr_t vstr;
@ -1438,11 +1440,11 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_
const byte *key = ++str;
while (*str != ')') {
if (str >= top) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
terse_str_format_value_error();
} else {
mp_raise_ValueError("incomplete format key");
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
#else
mp_raise_ValueError("incomplete format key");
#endif
}
++str;
}
@ -1502,11 +1504,11 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_
if (str >= top) {
incomplete_format:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
terse_str_format_value_error();
} else {
mp_raise_ValueError("incomplete format");
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
#else
mp_raise_ValueError("incomplete format");
#endif
}
// Tuple value lookup
@ -1588,13 +1590,13 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_
break;
default:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
terse_str_format_value_error();
} else {
mp_raise_msg_varg(&mp_type_ValueError,
"unsupported format character '%c' (0x%x) at index %d",
*str, *str, str - start_str);
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
#else
mp_raise_msg_varg(&mp_type_ValueError,
"unsupported format character '%c' (0x%x) at index %d",
*str, *str, str - start_str);
#endif
}
}
@ -2125,14 +2127,14 @@ bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2) {
}
STATIC NORETURN void bad_implicit_conversion(mp_obj_t self_in) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("can't convert to str implicitly");
} else {
const qstr src_name = mp_obj_get_type(self_in)->name;
mp_raise_msg_varg(&mp_type_TypeError,
"can't convert '%q' object to %q implicitly",
src_name, src_name == MP_QSTR_str ? MP_QSTR_bytes : MP_QSTR_str);
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("can't convert to str implicitly");
#else
const qstr src_name = mp_obj_get_type(self_in)->name;
mp_raise_msg_varg(&mp_type_TypeError,
"can't convert '%q' object to %q implicitly",
src_name, src_name == MP_QSTR_str ? MP_QSTR_bytes : MP_QSTR_str);
#endif
}
// use this if you will anyway convert the string to a qstr

View File

@ -348,14 +348,13 @@ mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, size
m_del(mp_obj_t, args2, 2 + n_args + 2 * n_kw);
}
if (init_ret != mp_const_none) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("__init__() should return None");
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"__init__() should return None, not '%s'", mp_obj_get_type_str(init_ret));
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("__init__() should return None");
#else
mp_raise_msg_varg(&mp_type_TypeError,
"__init__() should return None, not '%s'", mp_obj_get_type_str(init_ret));
#endif
}
}
// If the type had a native base that was not explicitly initialised
@ -864,12 +863,12 @@ mp_obj_t mp_obj_instance_call(mp_obj_t self_in, size_t n_args, size_t n_kw, cons
mp_obj_t member[2] = {MP_OBJ_NULL, MP_OBJ_NULL};
mp_obj_t call = mp_obj_instance_get_call(self_in, member);
if (call == MP_OBJ_NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("object not callable");
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"'%s' object isn't callable", mp_obj_get_type_str(self_in));
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("object not callable");
#else
mp_raise_msg_varg(&mp_type_TypeError,
"'%s' object isn't callable", mp_obj_get_type_str(self_in));
#endif
}
mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in);
if (call == MP_OBJ_SENTINEL) {
@ -989,11 +988,11 @@ STATIC mp_obj_t type_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp
mp_obj_type_t *self = MP_OBJ_TO_PTR(self_in);
if (self->make_new == NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("cannot create instance");
} else {
mp_raise_msg_varg(&mp_type_TypeError, "cannot create '%q' instances", self->name);
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("cannot create instance");
#else
mp_raise_msg_varg(&mp_type_TypeError, "cannot create '%q' instances", self->name);
#endif
}
// make new instance
@ -1111,12 +1110,12 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
mp_obj_type_t *t = MP_OBJ_TO_PTR(bases_items[i]);
// TODO: Verify with CPy, tested on function type
if (t->make_new == NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("type isn't an acceptable base type");
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"type '%q' isn't an acceptable base type", t->name);
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("type isn't an acceptable base type");
#else
mp_raise_msg_varg(&mp_type_TypeError,
"type '%q' isn't an acceptable base type", t->name);
#endif
}
#if ENABLE_SPECIAL_ACCESSORS
if (mp_obj_is_instance_type(t)) {

View File

@ -144,15 +144,16 @@ overflow:
}
value_error:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
{
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_obj_t exc = mp_obj_new_exception_msg(&mp_type_ValueError,
"invalid syntax for integer");
raise_exc(exc, lex);
} else if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL) {
#elif MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL
mp_obj_t exc = mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"invalid syntax for integer with base %d", base);
raise_exc(exc, lex);
} else {
#else
vstr_t vstr;
mp_print_t print;
vstr_init_print(&vstr, 50, &print);
@ -161,6 +162,7 @@ value_error:
mp_obj_t exc = mp_obj_new_exception_arg1(&mp_type_ValueError,
mp_obj_new_str_from_vstr(&mp_type_str, &vstr));
raise_exc(exc, lex);
#endif
}
}

View File

@ -185,11 +185,11 @@ mp_obj_t mp_load_global(qstr qst) {
#endif
elem = mp_map_lookup((mp_map_t *)&mp_module_builtins_globals.map, MP_OBJ_NEW_QSTR(qst), MP_MAP_LOOKUP);
if (elem == NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_NameError, "name not defined");
} else {
mp_raise_msg_varg(&mp_type_NameError, "name '%q' isn't defined", qst);
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_msg(&mp_type_NameError, "name not defined");
#else
mp_raise_msg_varg(&mp_type_NameError, "name '%q' isn't defined", qst);
#endif
}
}
return elem->value;
@ -285,22 +285,22 @@ mp_obj_t mp_unary_op(mp_unary_op_t op, mp_obj_t arg) {
}
// With MP_UNARY_OP_INT, mp_unary_op() becomes a fallback for mp_obj_get_int().
// In this case provide a more focused error message to not confuse, e.g. chr(1.0)
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
if (op == MP_UNARY_OP_INT) {
mp_raise_TypeError("can't convert to int");
} else {
mp_raise_TypeError("unsupported type for operator");
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
if (op == MP_UNARY_OP_INT) {
mp_raise_TypeError("can't convert to int");
} else {
if (op == MP_UNARY_OP_INT) {
mp_raise_msg_varg(&mp_type_TypeError,
"can't convert %s to int", mp_obj_get_type_str(arg));
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"unsupported type for %q: '%s'",
mp_unary_op_method_name[op], mp_obj_get_type_str(arg));
}
mp_raise_TypeError("unsupported type for operator");
}
#else
if (op == MP_UNARY_OP_INT) {
mp_raise_msg_varg(&mp_type_TypeError,
"can't convert %s to int", mp_obj_get_type_str(arg));
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"unsupported type for %q: '%s'",
mp_unary_op_method_name[op], mp_obj_get_type_str(arg));
}
#endif
}
}
@ -604,13 +604,13 @@ generic_binary_op:
}
unsupported_op:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("unsupported type for operator");
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"unsupported types for %q: '%s', '%s'",
mp_binary_op_method_name[op], mp_obj_get_type_str(lhs), mp_obj_get_type_str(rhs));
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("unsupported type for operator");
#else
mp_raise_msg_varg(&mp_type_TypeError,
"unsupported types for %q: '%s', '%s'",
mp_binary_op_method_name[op], mp_obj_get_type_str(lhs), mp_obj_get_type_str(rhs));
#endif
zero_division:
mp_raise_msg(&mp_type_ZeroDivisionError, "divide by zero");
@ -646,12 +646,12 @@ mp_obj_t mp_call_function_n_kw(mp_obj_t fun_in, size_t n_args, size_t n_kw, cons
return type->call(fun_in, n_args, n_kw, args);
}
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("object not callable");
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"'%s' object isn't callable", mp_obj_get_type_str(fun_in));
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("object not callable");
#else
mp_raise_msg_varg(&mp_type_TypeError,
"'%s' object isn't callable", mp_obj_get_type_str(fun_in));
#endif
}
// args contains: fun self/NULL arg(0) ... arg(n_args-2) arg(n_args-1) kw_key(0) kw_val(0) ... kw_key(n_kw-1) kw_val(n_kw-1)
@ -875,17 +875,17 @@ void mp_unpack_sequence(mp_obj_t seq_in, size_t num, mp_obj_t *items) {
return;
too_short:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_ValueError("wrong number of values to unpack");
} else {
mp_raise_msg_varg(&mp_type_ValueError, "need more than %d values to unpack", (int)seq_len);
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_ValueError("wrong number of values to unpack");
#else
mp_raise_msg_varg(&mp_type_ValueError, "need more than %d values to unpack", (int)seq_len);
#endif
too_long:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_ValueError("wrong number of values to unpack");
} else {
mp_raise_msg_varg(&mp_type_ValueError, "too many values to unpack (expected %d)", (int)num);
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_ValueError("wrong number of values to unpack");
#else
mp_raise_msg_varg(&mp_type_ValueError, "too many values to unpack (expected %d)", (int)num);
#endif
}
// unpacked items are stored in reverse order into the array pointed to by items
@ -942,11 +942,11 @@ void mp_unpack_ex(mp_obj_t seq_in, size_t num_in, mp_obj_t *items) {
return;
too_short:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_ValueError("wrong number of values to unpack");
} else {
mp_raise_msg_varg(&mp_type_ValueError, "need more than %d values to unpack", (int)seq_len);
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_ValueError("wrong number of values to unpack");
#else
mp_raise_msg_varg(&mp_type_ValueError, "need more than %d values to unpack", (int)seq_len);
#endif
}
mp_obj_t mp_load_attr(mp_obj_t base, qstr attr) {
@ -980,12 +980,12 @@ STATIC mp_obj_t checked_fun_call(mp_obj_t self_in, size_t n_args, size_t n_kw, c
if (n_args > 0) {
const mp_obj_type_t *arg0_type = mp_obj_get_type(args[0]);
if (arg0_type != self->type) {
if (MICROPY_ERROR_REPORTING != MICROPY_ERROR_REPORTING_DETAILED) {
mp_raise_TypeError("argument has wrong type");
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"argument should be a '%q' not a '%q'", self->type->name, arg0_type->name);
}
#if MICROPY_ERROR_REPORTING != MICROPY_ERROR_REPORTING_DETAILED
mp_raise_TypeError("argument has wrong type");
#else
mp_raise_msg_varg(&mp_type_TypeError,
"argument should be a '%q' not a '%q'", self->type->name, arg0_type->name);
#endif
}
}
return mp_call_function_n_kw(self->fun, n_args, n_kw, args);
@ -1105,20 +1105,20 @@ void mp_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest) {
if (dest[0] == MP_OBJ_NULL) {
// no attribute/method called attr
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_AttributeError, "no such attribute");
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_msg(&mp_type_AttributeError, "no such attribute");
#else
// following CPython, we give a more detailed error message for type objects
if (mp_obj_is_type(base, &mp_type_type)) {
mp_raise_msg_varg(&mp_type_AttributeError,
"type object '%q' has no attribute '%q'",
((mp_obj_type_t *)MP_OBJ_TO_PTR(base))->name, attr);
} else {
// following CPython, we give a more detailed error message for type objects
if (mp_obj_is_type(base, &mp_type_type)) {
mp_raise_msg_varg(&mp_type_AttributeError,
"type object '%q' has no attribute '%q'",
((mp_obj_type_t *)MP_OBJ_TO_PTR(base))->name, attr);
} else {
mp_raise_msg_varg(&mp_type_AttributeError,
"'%s' object has no attribute '%q'",
mp_obj_get_type_str(base), attr);
}
mp_raise_msg_varg(&mp_type_AttributeError,
"'%s' object has no attribute '%q'",
mp_obj_get_type_str(base), attr);
}
#endif
}
}
@ -1149,13 +1149,13 @@ void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) {
return;
}
}
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_AttributeError, "no such attribute");
} else {
mp_raise_msg_varg(&mp_type_AttributeError,
"'%s' object has no attribute '%q'",
mp_obj_get_type_str(base), attr);
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_msg(&mp_type_AttributeError, "no such attribute");
#else
mp_raise_msg_varg(&mp_type_AttributeError,
"'%s' object has no attribute '%q'",
mp_obj_get_type_str(base), attr);
#endif
}
mp_obj_t mp_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) {
@ -1194,12 +1194,13 @@ mp_obj_t mp_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) {
}
// object not iterable
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("object not iterable");
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"'%s' object isn't iterable", mp_obj_get_type_str(o_in));
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("object not iterable");
#else
mp_raise_msg_varg(&mp_type_TypeError,
"'%s' object isn't iterable", mp_obj_get_type_str(o_in));
#endif
}
// may return MP_OBJ_STOP_ITERATION as an optimisation instead of raise StopIteration()
@ -1216,12 +1217,12 @@ mp_obj_t mp_iternext_allow_raise(mp_obj_t o_in) {
// __next__ exists, call it and return its result
return mp_call_method_n_kw(0, 0, dest);
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("object not an iterator");
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"'%s' object isn't an iterator", mp_obj_get_type_str(o_in));
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("object not an iterator");
#else
mp_raise_msg_varg(&mp_type_TypeError,
"'%s' object isn't an iterator", mp_obj_get_type_str(o_in));
#endif
}
}
}
@ -1252,12 +1253,12 @@ mp_obj_t mp_iternext(mp_obj_t o_in) {
}
}
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("object not an iterator");
} else {
mp_raise_msg_varg(&mp_type_TypeError,
"'%s' object isn't an iterator", mp_obj_get_type_str(o_in));
}
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("object not an iterator");
#else
mp_raise_msg_varg(&mp_type_TypeError,
"'%s' object isn't an iterator", mp_obj_get_type_str(o_in));
#endif
}
}
}