In py/ use MP_ERROR_TEXT instead of translate
This commit is contained in:
parent
55874b6470
commit
acf350a1b7
@ -179,28 +179,28 @@ NORETURN void mp_arg_error_unimpl_kw(void) {
|
|||||||
|
|
||||||
mp_int_t mp_arg_validate_int(mp_int_t i, mp_int_t required_i, qstr arg_name) {
|
mp_int_t mp_arg_validate_int(mp_int_t i, mp_int_t required_i, qstr arg_name) {
|
||||||
if (i != required_i) {
|
if (i != required_i) {
|
||||||
mp_raise_ValueError_varg(translate("%q must be %d"), arg_name, required_i);
|
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be %d"), arg_name, required_i);
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_int_t mp_arg_validate_int_min(mp_int_t i, mp_int_t min, qstr arg_name) {
|
mp_int_t mp_arg_validate_int_min(mp_int_t i, mp_int_t min, qstr arg_name) {
|
||||||
if (i < min) {
|
if (i < min) {
|
||||||
mp_raise_ValueError_varg(translate("%q must be >= %d"), arg_name, min);
|
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be >= %d"), arg_name, min);
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_int_t mp_arg_validate_int_max(mp_int_t i, mp_int_t max, qstr arg_name) {
|
mp_int_t mp_arg_validate_int_max(mp_int_t i, mp_int_t max, qstr arg_name) {
|
||||||
if (i > max) {
|
if (i > max) {
|
||||||
mp_raise_ValueError_varg(translate("%q must be <= %d"), arg_name, max);
|
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be <= %d"), arg_name, max);
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_int_t mp_arg_validate_int_range(mp_int_t i, mp_int_t min, mp_int_t max, qstr arg_name) {
|
mp_int_t mp_arg_validate_int_range(mp_int_t i, mp_int_t min, mp_int_t max, qstr arg_name) {
|
||||||
if (i < min || i > max) {
|
if (i < min || i > max) {
|
||||||
mp_raise_ValueError_varg(translate("%q must be %d-%d"), arg_name, min, max);
|
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be %d-%d"), arg_name, min, max);
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@ -208,7 +208,7 @@ mp_int_t mp_arg_validate_int_range(mp_int_t i, mp_int_t min, mp_int_t max, qstr
|
|||||||
mp_float_t mp_arg_validate_type_float(mp_obj_t obj, qstr arg_name) {
|
mp_float_t mp_arg_validate_type_float(mp_obj_t obj, qstr arg_name) {
|
||||||
mp_float_t a_float;
|
mp_float_t a_float;
|
||||||
if (!mp_obj_get_float_maybe(obj, &a_float)) {
|
if (!mp_obj_get_float_maybe(obj, &a_float)) {
|
||||||
mp_raise_TypeError_varg(translate("%q must be of type %q, not %q"), arg_name, MP_QSTR_float, mp_obj_get_type(obj)->name);
|
mp_raise_TypeError_varg(MP_ERROR_TEXT("%q must be of type %q, not %q"), arg_name, MP_QSTR_float, mp_obj_get_type(obj)->name);
|
||||||
}
|
}
|
||||||
return a_float;
|
return a_float;
|
||||||
}
|
}
|
||||||
@ -220,7 +220,7 @@ mp_float_t mp_arg_validate_obj_float_range(mp_obj_t float_in, mp_int_t min, mp_i
|
|||||||
|
|
||||||
mp_float_t mp_arg_validate_float_range(mp_float_t f, mp_int_t min, mp_int_t max, qstr arg_name) {
|
mp_float_t mp_arg_validate_float_range(mp_float_t f, mp_int_t min, mp_int_t max, qstr arg_name) {
|
||||||
if (f < (mp_float_t)min || f > (mp_float_t)max) {
|
if (f < (mp_float_t)min || f > (mp_float_t)max) {
|
||||||
mp_raise_ValueError_varg(translate("%q must be %d-%d"), arg_name, min, max);
|
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be %d-%d"), arg_name, min, max);
|
||||||
}
|
}
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
@ -230,35 +230,35 @@ mp_float_t mp_arg_validate_obj_float_non_negative(mp_obj_t float_in, mp_float_t
|
|||||||
? default_for_null
|
? default_for_null
|
||||||
: mp_arg_validate_type_float(float_in, arg_name);
|
: mp_arg_validate_type_float(float_in, arg_name);
|
||||||
if (f < (mp_float_t)0.0) {
|
if (f < (mp_float_t)0.0) {
|
||||||
mp_raise_ValueError_varg(translate("%q must be >= %d"), arg_name, 0);
|
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be >= %d"), arg_name, 0);
|
||||||
}
|
}
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_uint_t mp_arg_validate_length_range(mp_uint_t length, mp_uint_t min, mp_uint_t max, qstr arg_name) {
|
mp_uint_t mp_arg_validate_length_range(mp_uint_t length, mp_uint_t min, mp_uint_t max, qstr arg_name) {
|
||||||
if (length < min || length > max) {
|
if (length < min || length > max) {
|
||||||
mp_raise_ValueError_varg(translate("%q length must be %d-%d"), arg_name, min, max);
|
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q length must be %d-%d"), arg_name, min, max);
|
||||||
}
|
}
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_uint_t mp_arg_validate_length_min(mp_uint_t length, mp_uint_t min, qstr arg_name) {
|
mp_uint_t mp_arg_validate_length_min(mp_uint_t length, mp_uint_t min, qstr arg_name) {
|
||||||
if (length < min) {
|
if (length < min) {
|
||||||
mp_raise_ValueError_varg(translate("%q length must be >= %d"), arg_name, min);
|
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q length must be >= %d"), arg_name, min);
|
||||||
}
|
}
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_uint_t mp_arg_validate_length_max(mp_uint_t length, mp_uint_t max, qstr arg_name) {
|
mp_uint_t mp_arg_validate_length_max(mp_uint_t length, mp_uint_t max, qstr arg_name) {
|
||||||
if (length > max) {
|
if (length > max) {
|
||||||
mp_raise_ValueError_varg(translate("%q length must be <= %d"), arg_name, max);
|
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q length must be <= %d"), arg_name, max);
|
||||||
}
|
}
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_uint_t mp_arg_validate_length(mp_uint_t length, mp_uint_t required_length, qstr arg_name) {
|
mp_uint_t mp_arg_validate_length(mp_uint_t length, mp_uint_t required_length, qstr arg_name) {
|
||||||
if (length != required_length) {
|
if (length != required_length) {
|
||||||
mp_raise_ValueError_varg(translate("%q length must be %d"), arg_name, required_length);
|
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q length must be %d"), arg_name, required_length);
|
||||||
}
|
}
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
@ -266,35 +266,35 @@ mp_uint_t mp_arg_validate_length(mp_uint_t length, mp_uint_t required_length, qs
|
|||||||
// int instead of uint because an index can be negative in some cases.
|
// int instead of uint because an index can be negative in some cases.
|
||||||
mp_int_t mp_arg_validate_index_range(mp_int_t index, mp_int_t min, mp_int_t max, qstr arg_name) {
|
mp_int_t mp_arg_validate_index_range(mp_int_t index, mp_int_t min, mp_int_t max, qstr arg_name) {
|
||||||
if (index < min || index > max) {
|
if (index < min || index > max) {
|
||||||
mp_raise_IndexError_varg(translate("%q out of range"), arg_name, min, max);
|
mp_raise_IndexError_varg(MP_ERROR_TEXT("%q out of range"), arg_name, min, max);
|
||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t mp_arg_validate_type(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_name) {
|
mp_obj_t mp_arg_validate_type(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_name) {
|
||||||
if (!mp_obj_is_type(obj, type)) {
|
if (!mp_obj_is_type(obj, type)) {
|
||||||
mp_raise_TypeError_varg(translate("%q must be of type %q, not %q"), arg_name, type->name, mp_obj_get_type(obj)->name);
|
mp_raise_TypeError_varg(MP_ERROR_TEXT("%q must be of type %q, not %q"), arg_name, type->name, mp_obj_get_type(obj)->name);
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t mp_arg_validate_type_in(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_name) {
|
mp_obj_t mp_arg_validate_type_in(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_name) {
|
||||||
if (!mp_obj_is_type(obj, type)) {
|
if (!mp_obj_is_type(obj, type)) {
|
||||||
mp_raise_TypeError_varg(translate("%q in %q must be of type %q, not %q"), MP_QSTR_object, arg_name, type->name, mp_obj_get_type(obj)->name);
|
mp_raise_TypeError_varg(MP_ERROR_TEXT("%q in %q must be of type %q, not %q"), MP_QSTR_object, arg_name, type->name, mp_obj_get_type(obj)->name);
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t mp_arg_validate_type_or_none(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_name) {
|
mp_obj_t mp_arg_validate_type_or_none(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_name) {
|
||||||
if (obj != mp_const_none && !mp_obj_is_type(obj, type)) {
|
if (obj != mp_const_none && !mp_obj_is_type(obj, type)) {
|
||||||
mp_raise_TypeError_varg(translate("%q must be of type %q or %q, not %q"), arg_name, type->name, MP_QSTR_None, mp_obj_get_type(obj)->name);
|
mp_raise_TypeError_varg(MP_ERROR_TEXT("%q must be of type %q or %q, not %q"), arg_name, type->name, MP_QSTR_None, mp_obj_get_type(obj)->name);
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t mp_arg_validate_type_string(mp_obj_t obj, qstr arg_name) {
|
mp_obj_t mp_arg_validate_type_string(mp_obj_t obj, qstr arg_name) {
|
||||||
if (!mp_obj_is_str(obj)) {
|
if (!mp_obj_is_str(obj)) {
|
||||||
mp_raise_TypeError_varg(translate("%q must be of type %q, not %q"), arg_name, MP_QSTR_str, mp_obj_get_type(obj)->name);
|
mp_raise_TypeError_varg(MP_ERROR_TEXT("%q must be of type %q, not %q"), arg_name, MP_QSTR_str, mp_obj_get_type(obj)->name);
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
@ -302,11 +302,11 @@ mp_obj_t mp_arg_validate_type_string(mp_obj_t obj, qstr arg_name) {
|
|||||||
mp_int_t mp_arg_validate_type_int(mp_obj_t obj, qstr arg_name) {
|
mp_int_t mp_arg_validate_type_int(mp_obj_t obj, qstr arg_name) {
|
||||||
mp_int_t an_int;
|
mp_int_t an_int;
|
||||||
if (!mp_obj_get_int_maybe(obj, &an_int)) {
|
if (!mp_obj_get_int_maybe(obj, &an_int)) {
|
||||||
mp_raise_TypeError_varg(translate("%q must be of type %q, not %q"), arg_name, MP_QSTR_int, mp_obj_get_type(obj)->name);
|
mp_raise_TypeError_varg(MP_ERROR_TEXT("%q must be of type %q, not %q"), arg_name, MP_QSTR_int, mp_obj_get_type(obj)->name);
|
||||||
}
|
}
|
||||||
return an_int;
|
return an_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
NORETURN void mp_arg_error_invalid(qstr arg_name) {
|
NORETURN void mp_arg_error_invalid(qstr arg_name) {
|
||||||
mp_raise_ValueError_varg(translate("Invalid %q"), arg_name);
|
mp_raise_ValueError_varg(MP_ERROR_TEXT("Invalid %q"), arg_name);
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ STATIC void mp_help_print_modules(void) {
|
|||||||
|
|
||||||
#if MICROPY_ENABLE_EXTERNAL_IMPORT
|
#if MICROPY_ENABLE_EXTERNAL_IMPORT
|
||||||
// let the user know there may be other modules available from the filesystem
|
// let the user know there may be other modules available from the filesystem
|
||||||
serial_write_compressed(translate("Plus any modules on the filesystem\n"));
|
serial_write_compressed(MP_ERROR_TEXT("Plus any modules on the filesystem\n"));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -138,10 +138,10 @@ STATIC void mp_help_print_obj(const mp_obj_t obj) {
|
|||||||
const mp_obj_type_t *type = mp_obj_get_type(obj);
|
const mp_obj_type_t *type = mp_obj_get_type(obj);
|
||||||
|
|
||||||
// try to print something sensible about the given object
|
// try to print something sensible about the given object
|
||||||
mp_cprintf(MP_PYTHON_PRINTER, translate("object "));
|
mp_cprintf(MP_PYTHON_PRINTER, MP_ERROR_TEXT("object "));
|
||||||
mp_obj_print(obj, PRINT_STR);
|
mp_obj_print(obj, PRINT_STR);
|
||||||
|
|
||||||
mp_cprintf(MP_PYTHON_PRINTER, translate(" is of type %q\n"), type->name);
|
mp_cprintf(MP_PYTHON_PRINTER, MP_ERROR_TEXT(" is of type %q\n"), type->name);
|
||||||
|
|
||||||
mp_map_t *map = NULL;
|
mp_map_t *map = NULL;
|
||||||
if (type == &mp_type_module) {
|
if (type == &mp_type_module) {
|
||||||
@ -168,7 +168,7 @@ STATIC mp_obj_t mp_builtin_help(size_t n_args, const mp_obj_t *args) {
|
|||||||
if (n_args == 0) {
|
if (n_args == 0) {
|
||||||
// print a general help message. Translate only works on single strings on one line.
|
// print a general help message. Translate only works on single strings on one line.
|
||||||
mp_cprintf(MP_PYTHON_PRINTER,
|
mp_cprintf(MP_PYTHON_PRINTER,
|
||||||
translate("Welcome to Adafruit CircuitPython %s!\n\nVisit circuitpython.org for more information.\n\nTo list built-in modules type `help(\"modules\")`.\n"),
|
MP_ERROR_TEXT("Welcome to Adafruit CircuitPython %s!\n\nVisit circuitpython.org for more information.\n\nTo list built-in modules type `help(\"modules\")`.\n"),
|
||||||
MICROPY_GIT_TAG);
|
MICROPY_GIT_TAG);
|
||||||
} else {
|
} else {
|
||||||
// try to print something sensible about the given object
|
// try to print something sensible about the given object
|
||||||
|
@ -2740,7 +2740,7 @@ STATIC void compile_yield_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
|
|||||||
pns = (mp_parse_node_struct_t *)pns->nodes[0];
|
pns = (mp_parse_node_struct_t *)pns->nodes[0];
|
||||||
#if MICROPY_PY_ASYNC_AWAIT
|
#if MICROPY_PY_ASYNC_AWAIT
|
||||||
if (comp->scope_cur->scope_flags & MP_SCOPE_FLAG_ASYNC) {
|
if (comp->scope_cur->scope_flags & MP_SCOPE_FLAG_ASYNC) {
|
||||||
compile_syntax_error(comp, (mp_parse_node_t)pns, translate("'yield from' inside async function"));
|
compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("'yield from' inside async function"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user