Always use preprocessor for MICROPY_ERROR_REPORTING
This ensures that only the translate("") alternative that will be used is seen after preprocessing. Improves the quality of the Huffman encoding and reduces binary size slightly. Also makes one "enhanced" error message only occur when ERROR_REPORTING_DETAILED: Instead of the word-for-word python3 error message "Type object has no attribute '%q'", the message will be "'type' object has no attribute '%q'". Also reduces binary size. (that's rolled into this commit as it was right next to a change to use the preprocessor for MICROPY_ERROR_REPORTING) Note that the odd semicolon after "value_error:" in parsenum.c is necessary due to a detail of the C grammar, in which a declaration cannot follow a label directly.
This commit is contained in:
parent
c06fc8e02d
commit
b2b8520880
@ -99,12 +99,12 @@ 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);
|
mp_map_elem_t *kw = mp_map_lookup(kws, MP_OBJ_NEW_QSTR(allowed[i].qst), MP_MAP_LOOKUP);
|
||||||
if (kw == NULL) {
|
if (kw == NULL) {
|
||||||
if (allowed[i].flags & MP_ARG_REQUIRED) {
|
if (allowed[i].flags & MP_ARG_REQUIRED) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_arg_error_terse_mismatch();
|
mp_arg_error_terse_mismatch();
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(
|
mp_raise_TypeError_varg(
|
||||||
translate("'%q' argument required"), allowed[i].qst);
|
translate("'%q' argument required"), allowed[i].qst);
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
out_vals[i] = allowed[i].defval;
|
out_vals[i] = allowed[i].defval;
|
||||||
continue;
|
continue;
|
||||||
@ -124,20 +124,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) {
|
if (pos_found < n_pos) {
|
||||||
extra_positional:
|
extra_positional:
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_arg_error_terse_mismatch();
|
mp_arg_error_terse_mismatch();
|
||||||
} else {
|
#else
|
||||||
// TODO better error message
|
// TODO better error message
|
||||||
mp_raise_TypeError(translate("extra positional arguments given"));
|
mp_raise_TypeError(translate("extra positional arguments given"));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
if (kws_found < kws->used) {
|
if (kws_found < kws->used) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_arg_error_terse_mismatch();
|
mp_arg_error_terse_mismatch();
|
||||||
} else {
|
#else
|
||||||
// TODO better error message
|
// TODO better error message
|
||||||
mp_raise_TypeError(translate("extra keyword arguments given"));
|
mp_raise_TypeError(translate("extra keyword arguments given"));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,12 +426,12 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
|
|||||||
mp_module_call_init(mod_name, module_obj);
|
mp_module_call_init(mod_name, module_obj);
|
||||||
} else {
|
} else {
|
||||||
// couldn't find the file, so fail
|
// couldn't find the file, so fail
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_ImportError(translate("module not found"));
|
mp_raise_ImportError(translate("module not found"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_msg_varg(&mp_type_ImportError,
|
mp_raise_msg_varg(&mp_type_ImportError,
|
||||||
translate("no module named '%q'"), mod_name);
|
translate("no module named '%q'"), mod_name);
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// found the file, so get the module
|
// found the file, so get the module
|
||||||
@ -538,12 +538,12 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Couldn't find the module, so fail
|
// Couldn't find the module, so fail
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_msg(&mp_type_ImportError, translate("module not found"));
|
mp_raise_msg(&mp_type_ImportError, translate("module not found"));
|
||||||
} else {
|
#else
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ImportError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ImportError,
|
||||||
translate("no module named '%q'"), module_name_qstr));
|
translate("no module named '%q'"), module_name_qstr));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // MICROPY_ENABLE_EXTERNAL_IMPORT
|
#endif // MICROPY_ENABLE_EXTERNAL_IMPORT
|
||||||
|
12
py/compile.c
12
py/compile.c
@ -2486,21 +2486,21 @@ STATIC void compile_atom_brace(compiler_t *comp, mp_parse_node_struct_t *pns) {
|
|||||||
compile_node(comp, pn_i);
|
compile_node(comp, pn_i);
|
||||||
if (is_dict) {
|
if (is_dict) {
|
||||||
if (!is_key_value) {
|
if (!is_key_value) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
compile_syntax_error(comp, (mp_parse_node_t)pns, translate("invalid syntax"));
|
compile_syntax_error(comp, (mp_parse_node_t)pns, translate("invalid syntax"));
|
||||||
} else {
|
#else
|
||||||
compile_syntax_error(comp, (mp_parse_node_t)pns, translate("expecting key:value for dict"));
|
compile_syntax_error(comp, (mp_parse_node_t)pns, translate("expecting key:value for dict"));
|
||||||
}
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EMIT(store_map);
|
EMIT(store_map);
|
||||||
} else {
|
} else {
|
||||||
if (is_key_value) {
|
if (is_key_value) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
compile_syntax_error(comp, (mp_parse_node_t)pns, translate("invalid syntax"));
|
compile_syntax_error(comp, (mp_parse_node_t)pns, translate("invalid syntax"));
|
||||||
} else {
|
#else
|
||||||
compile_syntax_error(comp, (mp_parse_node_t)pns, translate("expecting just a value for set"));
|
compile_syntax_error(comp, (mp_parse_node_t)pns, translate("expecting just a value for set"));
|
||||||
}
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -346,12 +346,12 @@ STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_TypeError(translate("ord expects a character"));
|
mp_raise_TypeError(translate("ord expects a character"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(
|
mp_raise_TypeError_varg(
|
||||||
translate("ord() expected a character, but string of length %d found"), (int)len);
|
translate("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);
|
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_ord_obj, mp_builtin_ord);
|
||||||
|
|
||||||
|
@ -92,13 +92,11 @@ STATIC const MP_DEFINE_STR_OBJ(platform_obj, MICROPY_PY_SYS_PLATFORM);
|
|||||||
|
|
||||||
// exit([retval]): raise SystemExit, with optional argument given to the exception
|
// exit([retval]): raise SystemExit, with optional argument given to the exception
|
||||||
STATIC mp_obj_t mp_sys_exit(size_t n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t mp_sys_exit(size_t n_args, const mp_obj_t *args) {
|
||||||
mp_obj_t exc;
|
|
||||||
if (n_args == 0) {
|
if (n_args == 0) {
|
||||||
exc = mp_obj_new_exception(&mp_type_SystemExit);
|
nlr_raise(mp_obj_new_exception(&mp_type_SystemExit));
|
||||||
} else {
|
} else {
|
||||||
mp_raise_arg1(&mp_type_SystemExit, args[0]);
|
mp_raise_arg1(&mp_type_SystemExit, args[0]);
|
||||||
}
|
}
|
||||||
nlr_raise(exc);
|
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_exit_obj, 0, 1, mp_sys_exit);
|
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_exit_obj, 0, 1, mp_sys_exit);
|
||||||
|
|
||||||
|
66
py/obj.c
66
py/obj.c
@ -262,12 +262,12 @@ mp_int_t mp_obj_get_int(mp_const_obj_t arg) {
|
|||||||
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) {
|
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) {
|
||||||
return mp_obj_int_get_checked(arg);
|
return mp_obj_int_get_checked(arg);
|
||||||
} else {
|
} else {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_TypeError_varg(translate("can't convert to %q"), MP_QSTR_int);
|
mp_raise_TypeError_varg(translate("can't convert to %q"), MP_QSTR_int);
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(
|
mp_raise_TypeError_varg(
|
||||||
translate("can't convert %q to %q"), mp_obj_get_type_qstr(arg), MP_QSTR_int);
|
translate("can't convert %q to %q"), mp_obj_get_type_qstr(arg), MP_QSTR_int);
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,12 +325,12 @@ mp_float_t mp_obj_get_float(mp_obj_t arg) {
|
|||||||
mp_float_t val;
|
mp_float_t val;
|
||||||
|
|
||||||
if (!mp_obj_get_float_maybe(arg, &val)) {
|
if (!mp_obj_get_float_maybe(arg, &val)) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_TypeError_varg(translate("can't convert to %q"), MP_QSTR_float);
|
mp_raise_TypeError_varg(translate("can't convert to %q"), MP_QSTR_float);
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(
|
mp_raise_TypeError_varg(
|
||||||
translate("can't convert %q to %q"), mp_obj_get_type_qstr(arg), MP_QSTR_float);
|
translate("can't convert %q to %q"), mp_obj_get_type_qstr(arg), MP_QSTR_float);
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
@ -358,12 +358,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)) {
|
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_complex)) {
|
||||||
mp_obj_complex_get(arg, real, imag);
|
mp_obj_complex_get(arg, real, imag);
|
||||||
} else {
|
} else {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_TypeError_varg(translate("can't convert to %q"), MP_QSTR_complex);
|
mp_raise_TypeError_varg(translate("can't convert to %q"), MP_QSTR_complex);
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(
|
mp_raise_TypeError_varg(
|
||||||
translate("can't convert %q to %q"), mp_obj_get_type_qstr(arg), MP_QSTR_complex);
|
translate("can't convert %q to %q"), mp_obj_get_type_qstr(arg), MP_QSTR_complex);
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -376,12 +376,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)) {
|
} else if (MP_OBJ_IS_TYPE(o, &mp_type_list)) {
|
||||||
mp_obj_list_get(o, len, items);
|
mp_obj_list_get(o, len, items);
|
||||||
} else {
|
} else {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_TypeError(translate("expected tuple/list"));
|
mp_raise_TypeError(translate("expected tuple/list"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(
|
mp_raise_TypeError_varg(
|
||||||
translate("object '%q' is not a tuple or list"), mp_obj_get_type_qstr(o));
|
translate("object '%q' is not a tuple or list"), mp_obj_get_type_qstr(o));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -390,12 +390,12 @@ void mp_obj_get_array_fixed_n(mp_obj_t o, size_t len, mp_obj_t **items) {
|
|||||||
size_t seq_len;
|
size_t seq_len;
|
||||||
mp_obj_get_array(o, &seq_len, items);
|
mp_obj_get_array(o, &seq_len, items);
|
||||||
if (seq_len != len) {
|
if (seq_len != len) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_ValueError(translate("tuple/list has wrong length"));
|
mp_raise_ValueError(translate("tuple/list has wrong length"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_ValueError_varg(translate("requested length %d but object has length %d"),
|
mp_raise_ValueError_varg(translate("requested length %d but object has length %d"),
|
||||||
(int)len, (int)seq_len);
|
(int)len, (int)seq_len);
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,13 +405,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)) {
|
if (MP_OBJ_IS_SMALL_INT(index)) {
|
||||||
i = MP_OBJ_SMALL_INT_VALUE(index);
|
i = MP_OBJ_SMALL_INT_VALUE(index);
|
||||||
} else if (!mp_obj_get_int_maybe(index, &i)) {
|
} else if (!mp_obj_get_int_maybe(index, &i)) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_TypeError(translate("indices must be integers"));
|
mp_raise_TypeError(translate("indices must be integers"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(
|
mp_raise_TypeError_varg(
|
||||||
translate("%q indices must be integers, not %q"),
|
translate("%q indices must be integers, not %q"),
|
||||||
type->name, mp_obj_get_type_qstr(index));
|
type->name, mp_obj_get_type_qstr(index));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
@ -425,12 +425,12 @@ size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (i < 0 || (mp_uint_t)i >= len) {
|
if (i < 0 || (mp_uint_t)i >= len) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_IndexError(translate("index out of range"));
|
mp_raise_IndexError(translate("index out of range"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_msg_varg(&mp_type_IndexError,
|
mp_raise_msg_varg(&mp_type_IndexError,
|
||||||
translate("%q index out of range"), type->name);
|
translate("%q index out of range"), type->name);
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -460,12 +460,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 mp_obj_len(mp_obj_t o_in) {
|
||||||
mp_obj_t len = mp_obj_len_maybe(o_in);
|
mp_obj_t len = mp_obj_len_maybe(o_in);
|
||||||
if (len == MP_OBJ_NULL) {
|
if (len == MP_OBJ_NULL) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_TypeError(translate("object has no len"));
|
mp_raise_TypeError(translate("object has no len"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(
|
mp_raise_TypeError_varg(
|
||||||
translate("object of type '%q' has no len()"), mp_obj_get_type_qstr(o_in));
|
translate("object of type '%q' has no len()"), mp_obj_get_type_qstr(o_in));
|
||||||
}
|
#endif
|
||||||
} else {
|
} else {
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
@ -503,26 +503,26 @@ mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (value == MP_OBJ_NULL) {
|
if (value == MP_OBJ_NULL) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_TypeError(translate("object does not support item deletion"));
|
mp_raise_TypeError(translate("object does not support item deletion"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(
|
mp_raise_TypeError_varg(
|
||||||
translate("'%q' object does not support item deletion"), mp_obj_get_type_qstr(base));
|
translate("'%q' object does not support item deletion"), mp_obj_get_type_qstr(base));
|
||||||
}
|
#endif
|
||||||
} else if (value == MP_OBJ_SENTINEL) {
|
} else if (value == MP_OBJ_SENTINEL) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_TypeError(translate("object is not subscriptable"));
|
mp_raise_TypeError(translate("object is not subscriptable"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(
|
mp_raise_TypeError_varg(
|
||||||
translate("'%q' object is not subscriptable"), mp_obj_get_type_qstr(base));
|
translate("'%q' object is not subscriptable"), mp_obj_get_type_qstr(base));
|
||||||
}
|
#endif
|
||||||
} else {
|
} else {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_TypeError(translate("object does not support item assignment"));
|
mp_raise_TypeError(translate("object does not support item assignment"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(
|
mp_raise_TypeError_varg(
|
||||||
translate("'%q' object does not support item assignment"), mp_obj_get_type_qstr(base));
|
translate("'%q' object does not support item assignment"), mp_obj_get_type_qstr(base));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,17 +102,17 @@ mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, const
|
|||||||
n_kw = kw_args->used;
|
n_kw = kw_args->used;
|
||||||
}
|
}
|
||||||
if (n_args + n_kw != num_fields) {
|
if (n_args + n_kw != num_fields) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_arg_error_terse_mismatch();
|
mp_arg_error_terse_mismatch();
|
||||||
} else if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL) {
|
#elif MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL
|
||||||
mp_raise_TypeError_varg(
|
mp_raise_TypeError_varg(
|
||||||
translate("function takes %d positional arguments but %d were given"),
|
translate("function takes %d positional arguments but %d were given"),
|
||||||
num_fields, n_args + n_kw);
|
num_fields, n_args + n_kw);
|
||||||
} else if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED) {
|
#else
|
||||||
mp_raise_TypeError_varg(
|
mp_raise_TypeError_varg(
|
||||||
translate("%q() takes %d positional arguments but %d were given"),
|
translate("%q() takes %d positional arguments but %d were given"),
|
||||||
type->base.name, num_fields, n_args + n_kw);
|
type->base.name, num_fields, n_args + n_kw);
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a tuple and set the type to this namedtuple
|
// Create a tuple and set the type to this namedtuple
|
||||||
@ -128,20 +128,20 @@ mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, const
|
|||||||
qstr kw = mp_obj_str_get_qstr(kw_args->table[i].key);
|
qstr kw = mp_obj_str_get_qstr(kw_args->table[i].key);
|
||||||
size_t id = mp_obj_namedtuple_find_field(type, kw);
|
size_t id = mp_obj_namedtuple_find_field(type, kw);
|
||||||
if (id == (size_t)-1) {
|
if (id == (size_t)-1) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_arg_error_terse_mismatch();
|
mp_arg_error_terse_mismatch();
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(
|
mp_raise_TypeError_varg(
|
||||||
translate("unexpected keyword argument '%q'"), kw);
|
translate("unexpected keyword argument '%q'"), kw);
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
if (tuple->items[id] != MP_OBJ_NULL) {
|
if (tuple->items[id] != MP_OBJ_NULL) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_arg_error_terse_mismatch();
|
mp_arg_error_terse_mismatch();
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(
|
mp_raise_TypeError_varg(
|
||||||
translate("function got multiple values for argument '%q'"), kw);
|
translate("function got multiple values for argument '%q'"), kw);
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
tuple->items[id] = kw_args->table[i].value;
|
tuple->items[id] = kw_args->table[i].value;
|
||||||
}
|
}
|
||||||
|
105
py/objstr.c
105
py/objstr.c
@ -971,11 +971,11 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
|
|||||||
vstr_add_byte(&vstr, '}');
|
vstr_add_byte(&vstr, '}');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
terse_str_format_value_error();
|
terse_str_format_value_error();
|
||||||
} else {
|
#else
|
||||||
mp_raise_ValueError(translate("single '}' encountered in format string"));
|
mp_raise_ValueError(translate("single '}' encountered in format string"));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
if (*str != '{') {
|
if (*str != '{') {
|
||||||
vstr_add_byte(&vstr, *str);
|
vstr_add_byte(&vstr, *str);
|
||||||
@ -1010,18 +1010,18 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
|
|||||||
if (str < top && (*str == 'r' || *str == 's')) {
|
if (str < top && (*str == 'r' || *str == 's')) {
|
||||||
conversion = *str++;
|
conversion = *str++;
|
||||||
} else {
|
} else {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
terse_str_format_value_error();
|
terse_str_format_value_error();
|
||||||
} else if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL) {
|
#elif MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL
|
||||||
mp_raise_ValueError(translate("bad conversion specifier"));
|
mp_raise_ValueError(translate("bad conversion specifier"));
|
||||||
} else {
|
#else
|
||||||
if (str >= top) {
|
if (str >= top) {
|
||||||
mp_raise_ValueError(
|
mp_raise_ValueError(
|
||||||
translate("end of format while looking for conversion specifier"));
|
translate("end of format while looking for conversion specifier"));
|
||||||
} else {
|
} else {
|
||||||
mp_raise_ValueError_varg(translate("unknown conversion specifier %c"), *str);
|
mp_raise_ValueError_varg(translate("unknown conversion specifier %c"), *str);
|
||||||
}
|
}
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1047,18 +1047,18 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (str >= top) {
|
if (str >= top) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
terse_str_format_value_error();
|
terse_str_format_value_error();
|
||||||
} else {
|
#else
|
||||||
mp_raise_ValueError(translate("unmatched '{' in format"));
|
mp_raise_ValueError(translate("unmatched '{' in format"));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
if (*str != '}') {
|
if (*str != '}') {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
terse_str_format_value_error();
|
:w
|
||||||
} else {
|
#else
|
||||||
mp_raise_ValueError(translate("expected ':' after format specifier"));
|
mp_raise_ValueError(translate("expected ':' after format specifier"));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t arg = mp_const_none;
|
mp_obj_t arg = mp_const_none;
|
||||||
@ -1067,12 +1067,12 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
if (MP_LIKELY(unichar_isdigit(*field_name))) {
|
if (MP_LIKELY(unichar_isdigit(*field_name))) {
|
||||||
if (*arg_i > 0) {
|
if (*arg_i > 0) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
terse_str_format_value_error();
|
terse_str_format_value_error();
|
||||||
} else {
|
#else
|
||||||
mp_raise_ValueError(
|
mp_raise_ValueError(
|
||||||
translate("can't switch from automatic field numbering to manual field specification"));
|
translate("can't switch from automatic field numbering to manual field specification"));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
field_name = str_to_int(field_name, field_name_top, &index);
|
field_name = str_to_int(field_name, field_name_top, &index);
|
||||||
if ((uint)index >= n_args - 1) {
|
if ((uint)index >= n_args - 1) {
|
||||||
@ -1096,12 +1096,12 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (*arg_i < 0) {
|
if (*arg_i < 0) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
terse_str_format_value_error();
|
terse_str_format_value_error();
|
||||||
} else {
|
#else
|
||||||
mp_raise_ValueError(
|
mp_raise_ValueError(
|
||||||
translate("can't switch from manual field specification to automatic field numbering"));
|
translate("can't switch from manual field specification to automatic field numbering"));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
if ((uint)*arg_i >= n_args - 1) {
|
if ((uint)*arg_i >= n_args - 1) {
|
||||||
mp_raise_IndexError_varg(translate("%q index out of range"), MP_QSTR_tuple);
|
mp_raise_IndexError_varg(translate("%q index out of range"), MP_QSTR_tuple);
|
||||||
@ -1189,11 +1189,11 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
|
|||||||
type = *s++;
|
type = *s++;
|
||||||
}
|
}
|
||||||
if (*s) {
|
if (*s) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
terse_str_format_value_error();
|
terse_str_format_value_error();
|
||||||
} else {
|
#else
|
||||||
mp_raise_ValueError(translate("invalid format specifier"));
|
mp_raise_ValueError(translate("invalid format specifier"));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
vstr_clear(&format_spec_vstr);
|
vstr_clear(&format_spec_vstr);
|
||||||
}
|
}
|
||||||
@ -1210,19 +1210,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 (flags & (PF_FLAG_SHOW_SIGN | PF_FLAG_SPACE_SIGN)) {
|
||||||
if (type == 's') {
|
if (type == 's') {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
terse_str_format_value_error();
|
terse_str_format_value_error();
|
||||||
} else {
|
#else
|
||||||
mp_raise_ValueError(translate("sign not allowed in string format specifier"));
|
mp_raise_ValueError(translate("sign not allowed in string format specifier"));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
if (type == 'c') {
|
if (type == 'c') {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
terse_str_format_value_error();
|
terse_str_format_value_error();
|
||||||
} else {
|
#else
|
||||||
mp_raise_ValueError(
|
mp_raise_ValueError(
|
||||||
translate("sign not allowed with integer format specifier 'c'"));
|
translate("sign not allowed with integer format specifier 'c'"));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1276,13 +1276,13 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
terse_str_format_value_error();
|
terse_str_format_value_error();
|
||||||
} else {
|
#else
|
||||||
mp_raise_ValueError_varg(
|
mp_raise_ValueError_varg(
|
||||||
translate("unknown format code '%c' for object of type '%q'"),
|
translate("unknown format code '%c' for object of type '%q'"),
|
||||||
type, mp_obj_get_type_qstr(arg));
|
type, mp_obj_get_type_qstr(arg));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1348,24 +1348,24 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
terse_str_format_value_error();
|
terse_str_format_value_error();
|
||||||
} else {
|
#else
|
||||||
mp_raise_ValueError_varg(
|
mp_raise_ValueError_varg(
|
||||||
translate("unknown format code '%c' for object of type '%q'"),
|
translate("unknown format code '%c' for object of type '%q'"),
|
||||||
type, mp_obj_get_type_qstr(arg));
|
type, mp_obj_get_type_qstr(arg));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// arg doesn't look like a number
|
// arg doesn't look like a number
|
||||||
|
|
||||||
if (align == '=') {
|
if (align == '=') {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
terse_str_format_value_error();
|
terse_str_format_value_error();
|
||||||
} else {
|
#else
|
||||||
mp_raise_ValueError(
|
mp_raise_ValueError(
|
||||||
translate("'=' alignment not allowed in string format specifier"));
|
translate("'=' alignment not allowed in string format specifier"));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@ -1384,13 +1384,13 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
terse_str_format_value_error();
|
terse_str_format_value_error();
|
||||||
} else {
|
#else
|
||||||
mp_raise_ValueError_varg(
|
mp_raise_ValueError_varg(
|
||||||
translate("unknown format code '%c' for object of type '%q'"),
|
translate("unknown format code '%c' for object of type '%q'"),
|
||||||
type, mp_obj_get_type_qstr(arg));
|
type, mp_obj_get_type_qstr(arg));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1442,11 +1442,11 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_
|
|||||||
const byte *key = ++str;
|
const byte *key = ++str;
|
||||||
while (*str != ')') {
|
while (*str != ')') {
|
||||||
if (str >= top) {
|
if (str >= top) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
terse_str_format_value_error();
|
terse_str_format_value_error();
|
||||||
} else {
|
#else
|
||||||
mp_raise_ValueError(translate("incomplete format key"));
|
mp_raise_ValueError(translate("incomplete format key"));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
++str;
|
++str;
|
||||||
}
|
}
|
||||||
@ -1500,11 +1500,11 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_
|
|||||||
|
|
||||||
if (str >= top) {
|
if (str >= top) {
|
||||||
incomplete_format:
|
incomplete_format:
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
terse_str_format_value_error();
|
terse_str_format_value_error();
|
||||||
} else {
|
#else
|
||||||
mp_raise_ValueError(translate("incomplete format"));
|
mp_raise_ValueError(translate("incomplete format"));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tuple value lookup
|
// Tuple value lookup
|
||||||
@ -1587,13 +1587,13 @@ not_enough_args:
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
terse_str_format_value_error();
|
terse_str_format_value_error();
|
||||||
} else {
|
#else
|
||||||
mp_raise_ValueError_varg(
|
mp_raise_ValueError_varg(
|
||||||
translate("unsupported format character '%c' (0x%x) at index %d"),
|
translate("unsupported format character '%c' (0x%x) at index %d"),
|
||||||
*str, *str, str - start_str);
|
*str, *str, str - start_str);
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2130,12 +2130,13 @@ bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC NORETURN void bad_implicit_conversion(mp_obj_t self_in) {
|
STATIC NORETURN void bad_implicit_conversion(mp_obj_t self_in) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_TypeError(translate("can't convert to str implicitly"));
|
mp_raise_TypeError(translate("can't convert to str implicitly"));
|
||||||
} else {
|
#else
|
||||||
const qstr src_name = mp_obj_get_type_qstr(self_in);
|
const qstr src_name = mp_obj_get_type_qstr(self_in);
|
||||||
mp_raise_TypeError_varg(translate("can't convert '%q' object to %q implicitly"),
|
mp_raise_TypeError_varg(translate("can't convert '%q' object to %q implicitly"),
|
||||||
src_name, src_name == MP_QSTR_str ? MP_QSTR_bytes : MP_QSTR_str);
|
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
|
// use this if you will anyway convert the string to a qstr
|
||||||
|
24
py/objtype.c
24
py/objtype.c
@ -373,12 +373,12 @@ mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, cons
|
|||||||
m_del(mp_obj_t, args2, 2 + n_args + 2 * n_kw);
|
m_del(mp_obj_t, args2, 2 + n_args + 2 * n_kw);
|
||||||
}
|
}
|
||||||
if (init_ret != mp_const_none) {
|
if (init_ret != mp_const_none) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_TypeError(translate("__init__() should return None"));
|
mp_raise_TypeError(translate("__init__() should return None"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(translate("__init__() should return None, not '%q'"),
|
mp_raise_TypeError_varg(translate("__init__() should return None, not '%q'"),
|
||||||
mp_obj_get_type_qstr(init_ret));
|
mp_obj_get_type_qstr(init_ret));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -888,12 +888,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 member[2] = {MP_OBJ_NULL, MP_OBJ_NULL};
|
||||||
mp_obj_t call = mp_obj_instance_get_call(self_in, member);
|
mp_obj_t call = mp_obj_instance_get_call(self_in, member);
|
||||||
if (call == MP_OBJ_NULL) {
|
if (call == MP_OBJ_NULL) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_TypeError(translate("object not callable"));
|
mp_raise_TypeError(translate("object not callable"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(translate("'%q' object is not callable"),
|
mp_raise_TypeError_varg(translate("'%q' object is not callable"),
|
||||||
mp_obj_get_type_qstr(self_in));
|
mp_obj_get_type_qstr(self_in));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in);
|
mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
if (call == MP_OBJ_SENTINEL) {
|
if (call == MP_OBJ_SENTINEL) {
|
||||||
@ -1024,11 +1024,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);
|
mp_obj_type_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
|
|
||||||
if (self->make_new == NULL) {
|
if (self->make_new == NULL) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_TypeError(translate("cannot create instance"));
|
mp_raise_TypeError(translate("cannot create instance"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(translate("cannot create '%q' instances"), self->name);
|
mp_raise_TypeError_varg(translate("cannot create '%q' instances"), self->name);
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a map directly from the given args array and make a new instance
|
// create a map directly from the given args array and make a new instance
|
||||||
@ -1134,12 +1134,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]);
|
mp_obj_type_t *t = MP_OBJ_TO_PTR(bases_items[i]);
|
||||||
// TODO: Verify with CPy, tested on function type
|
// TODO: Verify with CPy, tested on function type
|
||||||
if (t->make_new == NULL) {
|
if (t->make_new == NULL) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_TypeError(translate("type is not an acceptable base type"));
|
mp_raise_TypeError(translate("type is not an acceptable base type"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(
|
mp_raise_TypeError_varg(
|
||||||
translate("type '%q' is not an acceptable base type"), t->name);
|
translate("type '%q' is not an acceptable base type"), t->name);
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
#if ENABLE_SPECIAL_ACCESSORS
|
#if ENABLE_SPECIAL_ACCESSORS
|
||||||
if (mp_obj_is_instance_type(t)) {
|
if (mp_obj_is_instance_type(t)) {
|
||||||
|
@ -145,16 +145,16 @@ overflow:
|
|||||||
goto have_ret_val;
|
goto have_ret_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
value_error:
|
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,
|
mp_obj_t exc = mp_obj_new_exception_msg(&mp_type_ValueError,
|
||||||
translate("invalid syntax for integer"));
|
translate("invalid syntax for integer"));
|
||||||
raise_exc(exc, lex);
|
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,
|
mp_obj_t exc = mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||||
translate("invalid syntax for integer with base %d"), base);
|
translate("invalid syntax for integer with base %d"), base);
|
||||||
raise_exc(exc, lex);
|
raise_exc(exc, lex);
|
||||||
} else {
|
#else
|
||||||
vstr_t vstr;
|
vstr_t vstr;
|
||||||
mp_print_t print;
|
mp_print_t print;
|
||||||
vstr_init_print(&vstr, 50, &print);
|
vstr_init_print(&vstr, 50, &print);
|
||||||
@ -163,7 +163,7 @@ value_error:
|
|||||||
mp_obj_t exc = mp_obj_new_exception_arg1(&mp_type_ValueError,
|
mp_obj_t exc = mp_obj_new_exception_arg1(&mp_type_ValueError,
|
||||||
mp_obj_new_str_from_vstr(&mp_type_str, &vstr));
|
mp_obj_new_str_from_vstr(&mp_type_str, &vstr));
|
||||||
raise_exc(exc, lex);
|
raise_exc(exc, lex);
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
76
py/runtime.c
76
py/runtime.c
@ -177,12 +177,12 @@ mp_obj_t mp_load_global(qstr qst) {
|
|||||||
#endif
|
#endif
|
||||||
elem = mp_map_lookup((mp_map_t*)&mp_module_builtins_globals.map, MP_OBJ_NEW_QSTR(qst), MP_MAP_LOOKUP);
|
elem = mp_map_lookup((mp_map_t*)&mp_module_builtins_globals.map, MP_OBJ_NEW_QSTR(qst), MP_MAP_LOOKUP);
|
||||||
if (elem == NULL) {
|
if (elem == NULL) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_msg(&mp_type_NameError, translate("name not defined"));
|
mp_raise_msg(&mp_type_NameError, translate("name not defined"));
|
||||||
} else {
|
#else
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_NameError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_NameError,
|
||||||
translate("name '%q' is not defined"), qst));
|
translate("name '%q' is not defined"), qst));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return elem->value;
|
return elem->value;
|
||||||
@ -275,13 +275,13 @@ mp_obj_t mp_unary_op(mp_unary_op_t op, mp_obj_t arg) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_TypeError(translate("unsupported type for operator"));
|
mp_raise_TypeError(translate("unsupported type for operator"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(
|
mp_raise_TypeError_varg(
|
||||||
translate("unsupported type for %q: '%q'"),
|
translate("unsupported type for %q: '%q'"),
|
||||||
mp_unary_op_method_name[op], mp_obj_get_type_qstr(arg));
|
mp_unary_op_method_name[op], mp_obj_get_type_qstr(arg));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -582,13 +582,13 @@ generic_binary_op:
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsupported_op:
|
unsupported_op:
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_TypeError(translate("unsupported type for operator"));
|
mp_raise_TypeError(translate("unsupported type for operator"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(
|
mp_raise_TypeError_varg(
|
||||||
translate("unsupported types for %q: '%q', '%q'"),
|
translate("unsupported types for %q: '%q', '%q'"),
|
||||||
mp_binary_op_method_name[op], mp_obj_get_type_qstr(lhs), mp_obj_get_type_qstr(rhs));
|
mp_binary_op_method_name[op], mp_obj_get_type_qstr(lhs), mp_obj_get_type_qstr(rhs));
|
||||||
}
|
#endif
|
||||||
|
|
||||||
zero_division:
|
zero_division:
|
||||||
mp_raise_msg(&mp_type_ZeroDivisionError, translate("division by zero"));
|
mp_raise_msg(&mp_type_ZeroDivisionError, translate("division by zero"));
|
||||||
@ -624,11 +624,11 @@ 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);
|
return type->call(fun_in, n_args, n_kw, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_TypeError(translate("object not callable"));
|
mp_raise_TypeError(translate("object not callable"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(translate("'%q' object is not callable"), mp_obj_get_type_qstr(fun_in));
|
mp_raise_TypeError_varg(translate("'%q' object is not callable"), mp_obj_get_type_qstr(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)
|
// 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)
|
||||||
@ -852,19 +852,19 @@ void mp_unpack_sequence(mp_obj_t seq_in, size_t num, mp_obj_t *items) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
too_short:
|
too_short:
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_ValueError(translate("wrong number of values to unpack"));
|
mp_raise_ValueError(translate("wrong number of values to unpack"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_ValueError_varg(translate("need more than %d values to unpack"),
|
mp_raise_ValueError_varg(translate("need more than %d values to unpack"),
|
||||||
(int)seq_len);
|
(int)seq_len);
|
||||||
}
|
#endif
|
||||||
too_long:
|
too_long:
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_ValueError(translate("wrong number of values to unpack"));
|
mp_raise_ValueError(translate("wrong number of values to unpack"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_ValueError_varg(translate("too many values to unpack (expected %d)"),
|
mp_raise_ValueError_varg(translate("too many values to unpack (expected %d)"),
|
||||||
(int)num);
|
(int)num);
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// unpacked items are stored in reverse order into the array pointed to by items
|
// unpacked items are stored in reverse order into the array pointed to by items
|
||||||
@ -916,12 +916,12 @@ void mp_unpack_ex(mp_obj_t seq_in, size_t num_in, mp_obj_t *items) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
too_short:
|
too_short:
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_ValueError(translate("wrong number of values to unpack"));
|
mp_raise_ValueError(translate("wrong number of values to unpack"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_ValueError_varg(translate("need more than %d values to unpack"),
|
mp_raise_ValueError_varg(translate("need more than %d values to unpack"),
|
||||||
(int)seq_len);
|
(int)seq_len);
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t mp_load_attr(mp_obj_t base, qstr attr) {
|
mp_obj_t mp_load_attr(mp_obj_t base, qstr attr) {
|
||||||
@ -1094,9 +1094,9 @@ void mp_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest) {
|
|||||||
|
|
||||||
if (dest[0] == MP_OBJ_NULL) {
|
if (dest[0] == MP_OBJ_NULL) {
|
||||||
// no attribute/method called attr
|
// no attribute/method called attr
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_AttributeError(translate("no such attribute"));
|
mp_raise_AttributeError(translate("no such attribute"));
|
||||||
} else {
|
#elif MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
|
||||||
// following CPython, we give a more detailed error message for type objects
|
// following CPython, we give a more detailed error message for type objects
|
||||||
if (MP_OBJ_IS_TYPE(base, &mp_type_type)) {
|
if (MP_OBJ_IS_TYPE(base, &mp_type_type)) {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_AttributeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_AttributeError,
|
||||||
@ -1107,7 +1107,11 @@ void mp_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest) {
|
|||||||
translate("'%q' object has no attribute '%q'"),
|
translate("'%q' object has no attribute '%q'"),
|
||||||
mp_obj_get_type_qstr(base), attr));
|
mp_obj_get_type_qstr(base), attr));
|
||||||
}
|
}
|
||||||
}
|
#else
|
||||||
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_AttributeError,
|
||||||
|
translate("'%q' object has no attribute '%q'"),
|
||||||
|
mp_obj_get_type_qstr(base), attr));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1168,13 +1172,13 @@ void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_AttributeError(translate("no such attribute"));
|
mp_raise_AttributeError(translate("no such attribute"));
|
||||||
} else {
|
#else
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_AttributeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_AttributeError,
|
||||||
translate("'%q' object cannot assign attribute '%q'"),
|
translate("'%q' object cannot assign attribute '%q'"),
|
||||||
mp_obj_get_type_qstr(base), attr));
|
mp_obj_get_type_qstr(base), attr));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t mp_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) {
|
mp_obj_t mp_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) {
|
||||||
@ -1209,12 +1213,12 @@ mp_obj_t mp_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// object not iterable
|
// object not iterable
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_TypeError(translate("object not iterable"));
|
mp_raise_TypeError(translate("object not iterable"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(
|
mp_raise_TypeError_varg(
|
||||||
translate("'%q' object is not iterable"), mp_obj_get_type_qstr(o_in));
|
translate("'%q' object is not iterable"), mp_obj_get_type_qstr(o_in));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// may return MP_OBJ_STOP_ITERATION as an optimisation instead of raise StopIteration()
|
// may return MP_OBJ_STOP_ITERATION as an optimisation instead of raise StopIteration()
|
||||||
@ -1231,12 +1235,12 @@ mp_obj_t mp_iternext_allow_raise(mp_obj_t o_in) {
|
|||||||
// __next__ exists, call it and return its result
|
// __next__ exists, call it and return its result
|
||||||
return mp_call_method_n_kw(0, 0, dest);
|
return mp_call_method_n_kw(0, 0, dest);
|
||||||
} else {
|
} else {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_TypeError(translate("object not an iterator"));
|
mp_raise_TypeError(translate("object not an iterator"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(translate("'%q' object is not an iterator"),
|
mp_raise_TypeError_varg(translate("'%q' object is not an iterator"),
|
||||||
mp_obj_get_type_qstr(o_in));
|
mp_obj_get_type_qstr(o_in));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1267,12 +1271,12 @@ mp_obj_t mp_iternext(mp_obj_t o_in) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
mp_raise_TypeError(translate("object not an iterator"));
|
mp_raise_TypeError(translate("object not an iterator"));
|
||||||
} else {
|
#else
|
||||||
mp_raise_TypeError_varg(translate("'%q' object is not an iterator"),
|
mp_raise_TypeError_varg(translate("'%q' object is not an iterator"),
|
||||||
mp_obj_get_type_qstr(o_in));
|
mp_obj_get_type_qstr(o_in));
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user