py: Shorten error messages by using contractions and some rewording.

This commit is contained in:
Damien George 2018-06-20 21:02:11 +10:00
parent 0a36a80f96
commit b01f66c5f1
18 changed files with 36 additions and 36 deletions

View File

@ -41,7 +41,7 @@ void mp_arg_check_num_sig(size_t n_args, size_t n_kw, uint32_t sig) {
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("function does not take keyword arguments"); mp_raise_TypeError("function doesn't take keyword arguments");
} }
} }

View File

@ -2826,7 +2826,7 @@ STATIC void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn
bool added; bool added;
id_info_t *id_info = scope_find_or_add_id(comp->scope_cur, param_name, &added); id_info_t *id_info = scope_find_or_add_id(comp->scope_cur, param_name, &added);
if (!added) { if (!added) {
compile_syntax_error(comp, pn, "name reused for argument"); compile_syntax_error(comp, pn, "argument name reused");
return; return;
} }
id_info->kind = ID_INFO_KIND_LOCAL; id_info->kind = ID_INFO_KIND_LOCAL;

View File

@ -301,7 +301,7 @@ STATIC uint32_t get_arg_i(emit_inline_asm_t *emit, const char *op, mp_parse_node
} }
uint32_t i = mp_obj_get_int_truncated(o); uint32_t i = mp_obj_get_int_truncated(o);
if ((i & (~fit_mask)) != 0) { if ((i & (~fit_mask)) != 0) {
emit_inline_thumb_error_exc(emit, mp_obj_new_exception_msg_varg(&mp_type_SyntaxError, "'%s' integer 0x%x does not fit in mask 0x%x", op, i, fit_mask)); emit_inline_thumb_error_exc(emit, mp_obj_new_exception_msg_varg(&mp_type_SyntaxError, "'%s' integer 0x%x doesn't fit in mask 0x%x", op, i, fit_mask));
return 0; return 0;
} }
return i; return i;

View File

@ -171,7 +171,7 @@ STATIC uint32_t get_arg_i(emit_inline_asm_t *emit, const char *op, mp_parse_node
} }
uint32_t i = mp_obj_get_int_truncated(o); uint32_t i = mp_obj_get_int_truncated(o);
if (min != max && ((int)i < min || (int)i > max)) { if (min != max && ((int)i < min || (int)i > max)) {
emit_inline_xtensa_error_exc(emit, mp_obj_new_exception_msg_varg(&mp_type_SyntaxError, "'%s' integer %d is not within range %d..%d", op, i, min, max)); emit_inline_xtensa_error_exc(emit, mp_obj_new_exception_msg_varg(&mp_type_SyntaxError, "'%s' integer %d isn't within range %d..%d", op, i, min, max));
return 0; return 0;
} }
return i; return i;

View File

@ -187,7 +187,7 @@ STATIC mp_obj_t mp_math_log(size_t n_args, const mp_obj_t *args) {
if (base <= (mp_float_t)0.0) { if (base <= (mp_float_t)0.0) {
math_error(); math_error();
} else if (base == (mp_float_t)1.0) { } else if (base == (mp_float_t)1.0) {
mp_raise_msg(&mp_type_ZeroDivisionError, "division by zero"); mp_raise_msg(&mp_type_ZeroDivisionError, "divide by zero");
} }
return mp_obj_new_float(l / MICROPY_FLOAT_C_FUN(log)(base)); return mp_obj_new_float(l / MICROPY_FLOAT_C_FUN(log)(base));
} }

View File

@ -353,7 +353,7 @@ void mp_obj_get_array(mp_obj_t o, size_t *len, mp_obj_t **items) {
mp_raise_TypeError("expected tuple/list"); mp_raise_TypeError("expected tuple/list");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"object '%s' is not a tuple or list", mp_obj_get_type_str(o))); "object '%s' isn't a tuple or list", mp_obj_get_type_str(o)));
} }
} }
} }
@ -475,24 +475,24 @@ 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("object does not support item deletion"); mp_raise_TypeError("object doesn't support item deletion");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"'%s' object does not support item deletion", mp_obj_get_type_str(base))); "'%s' object doesn't support item deletion", mp_obj_get_type_str(base)));
} }
} 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("object is not subscriptable"); mp_raise_TypeError("object isn't subscriptable");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"'%s' object is not subscriptable", mp_obj_get_type_str(base))); "'%s' object isn't subscriptable", mp_obj_get_type_str(base)));
} }
} else { } else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("object does not support item assignment"); mp_raise_TypeError("object doesn't support item assignment");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"'%s' object does not support item assignment", mp_obj_get_type_str(base))); "'%s' object doesn't support item assignment", mp_obj_get_type_str(base)));
} }
} }
} }

View File

@ -195,13 +195,13 @@ mp_obj_t mp_obj_complex_binary_op(mp_binary_op_t op, mp_float_t lhs_real, mp_flo
} }
case MP_BINARY_OP_FLOOR_DIVIDE: case MP_BINARY_OP_FLOOR_DIVIDE:
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE: case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE:
mp_raise_TypeError("can't do truncated division of a complex number"); mp_raise_TypeError("can't truncate-divide a complex number");
case MP_BINARY_OP_TRUE_DIVIDE: case MP_BINARY_OP_TRUE_DIVIDE:
case MP_BINARY_OP_INPLACE_TRUE_DIVIDE: case MP_BINARY_OP_INPLACE_TRUE_DIVIDE:
if (rhs_imag == 0) { if (rhs_imag == 0) {
if (rhs_real == 0) { if (rhs_real == 0) {
mp_raise_msg(&mp_type_ZeroDivisionError, "complex division by zero"); mp_raise_msg(&mp_type_ZeroDivisionError, "complex divide by zero");
} }
lhs_real /= rhs_real; lhs_real /= rhs_real;
lhs_imag /= rhs_real; lhs_imag /= rhs_real;

View File

@ -262,7 +262,7 @@ mp_obj_t mp_obj_float_binary_op(mp_binary_op_t op, mp_float_t lhs_val, mp_obj_t
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE: case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE:
if (rhs_val == 0) { if (rhs_val == 0) {
zero_division_error: zero_division_error:
mp_raise_msg(&mp_type_ZeroDivisionError, "division by zero"); mp_raise_msg(&mp_type_ZeroDivisionError, "divide by zero");
} }
// Python specs require that x == (x//y)*y + (x%y) so we must // Python specs require that x == (x//y)*y + (x%y) so we must
// call divmod to compute the correct floor division, which // call divmod to compute the correct floor division, which

View File

@ -217,7 +217,7 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i
} }
zero_division: zero_division:
mp_raise_msg(&mp_type_ZeroDivisionError, "division by zero"); mp_raise_msg(&mp_type_ZeroDivisionError, "divide by zero");
} }
mp_obj_t mp_obj_new_int(mp_int_t value) { mp_obj_t mp_obj_new_int(mp_int_t value) {

View File

@ -225,7 +225,7 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE: { case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE: {
if (mpz_is_zero(zrhs)) { if (mpz_is_zero(zrhs)) {
zero_division_error: zero_division_error:
mp_raise_msg(&mp_type_ZeroDivisionError, "division by zero"); mp_raise_msg(&mp_type_ZeroDivisionError, "divide by zero");
} }
mpz_t rem; mpz_init_zero(&rem); mpz_t rem; mpz_init_zero(&rem);
mpz_divmod_inpl(&res->mpz, &rem, zlhs, zrhs); mpz_divmod_inpl(&res->mpz, &rem, zlhs, zrhs);

View File

@ -1411,7 +1411,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_
// Dictionary value lookup // Dictionary value lookup
if (*str == '(') { if (*str == '(') {
if (dict == MP_OBJ_NULL) { if (dict == MP_OBJ_NULL) {
mp_raise_TypeError("format requires a dict"); mp_raise_TypeError("format needs a dict");
} }
arg_i = 1; // we used up the single dict argument arg_i = 1; // we used up the single dict argument
const byte *key = ++str; const byte *key = ++str;
@ -1486,7 +1486,7 @@ incomplete_format:
if (arg == MP_OBJ_NULL) { if (arg == MP_OBJ_NULL) {
if (arg_i >= n_args) { if (arg_i >= n_args) {
not_enough_args: not_enough_args:
mp_raise_TypeError("not enough arguments for format string"); mp_raise_TypeError("format string needs more arguments");
} }
arg = args[arg_i++]; arg = args[arg_i++];
} }
@ -1496,14 +1496,14 @@ not_enough_args:
size_t slen; size_t slen;
const char *s = mp_obj_str_get_data(arg, &slen); const char *s = mp_obj_str_get_data(arg, &slen);
if (slen != 1) { if (slen != 1) {
mp_raise_TypeError("%%c requires int or char"); mp_raise_TypeError("%%c needs int or char");
} }
mp_print_strn(&print, s, 1, flags, ' ', width); mp_print_strn(&print, s, 1, flags, ' ', width);
} else if (arg_looks_integer(arg)) { } else if (arg_looks_integer(arg)) {
char ch = mp_obj_get_int(arg); char ch = mp_obj_get_int(arg);
mp_print_strn(&print, &ch, 1, flags, ' ', width); mp_print_strn(&print, &ch, 1, flags, ' ', width);
} else { } else {
mp_raise_TypeError("integer required"); mp_raise_TypeError("integer needed");
} }
break; break;
@ -1573,7 +1573,7 @@ not_enough_args:
} }
if (arg_i != n_args) { if (arg_i != n_args) {
mp_raise_TypeError("not all arguments converted during string formatting"); mp_raise_TypeError("format string didn't convert all arguments");
} }
return mp_obj_new_str_from_vstr(is_bytes ? &mp_type_bytes : &mp_type_str, &vstr); return mp_obj_new_str_from_vstr(is_bytes ? &mp_type_bytes : &mp_type_str, &vstr);

View File

@ -863,7 +863,7 @@ mp_obj_t mp_obj_instance_call(mp_obj_t self_in, size_t n_args, size_t n_kw, cons
mp_raise_TypeError("object not callable"); mp_raise_TypeError("object not callable");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"'%s' object is not callable", mp_obj_get_type_str(self_in))); "'%s' object isn't callable", mp_obj_get_type_str(self_in)));
} }
} }
mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in);
@ -1090,10 +1090,10 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
// 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("type is not an acceptable base type"); mp_raise_TypeError("type isn't an acceptable base type");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"type '%q' is not an acceptable base type", t->name)); "type '%q' isn't an acceptable base type", t->name));
} }
} }
#if ENABLE_SPECIAL_ACCESSORS #if ENABLE_SPECIAL_ACCESSORS

View File

@ -1145,7 +1145,7 @@ mp_parse_tree_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) {
"unexpected indent"); "unexpected indent");
} else if (lex->tok_kind == MP_TOKEN_DEDENT_MISMATCH) { } else if (lex->tok_kind == MP_TOKEN_DEDENT_MISMATCH) {
exc = mp_obj_new_exception_msg(&mp_type_IndentationError, exc = mp_obj_new_exception_msg(&mp_type_IndentationError,
"unindent does not match any outer indentation level"); "unindent doesn't match any outer indent level");
} else { } else {
exc = mp_obj_new_exception_msg(&mp_type_SyntaxError, exc = mp_obj_new_exception_msg(&mp_type_SyntaxError,
"invalid syntax"); "invalid syntax");

View File

@ -171,7 +171,7 @@ mp_obj_t mp_load_global(qstr qst) {
mp_raise_msg(&mp_type_NameError, "name not defined"); mp_raise_msg(&mp_type_NameError, "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,
"name '%q' is not defined", qst)); "name '%q' isn't defined", qst));
} }
} }
} }
@ -581,7 +581,7 @@ unsupported_op:
} }
zero_division: zero_division:
mp_raise_msg(&mp_type_ZeroDivisionError, "division by zero"); mp_raise_msg(&mp_type_ZeroDivisionError, "divide by zero");
} }
mp_obj_t mp_call_function_0(mp_obj_t fun) { mp_obj_t mp_call_function_0(mp_obj_t fun) {
@ -618,7 +618,7 @@ mp_obj_t mp_call_function_n_kw(mp_obj_t fun_in, size_t n_args, size_t n_kw, cons
mp_raise_TypeError("object not callable"); mp_raise_TypeError("object not callable");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"'%s' object is not callable", mp_obj_get_type_str(fun_in))); "'%s' object isn't callable", mp_obj_get_type_str(fun_in)));
} }
} }
@ -1157,7 +1157,7 @@ mp_obj_t mp_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) {
mp_raise_TypeError("object not iterable"); mp_raise_TypeError("object not iterable");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"'%s' object is not iterable", mp_obj_get_type_str(o_in))); "'%s' object isn't iterable", mp_obj_get_type_str(o_in)));
} }
} }
@ -1179,7 +1179,7 @@ mp_obj_t mp_iternext_allow_raise(mp_obj_t o_in) {
mp_raise_TypeError("object not an iterator"); mp_raise_TypeError("object not an iterator");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"'%s' object is not an iterator", mp_obj_get_type_str(o_in))); "'%s' object isn't an iterator", mp_obj_get_type_str(o_in)));
} }
} }
} }
@ -1215,7 +1215,7 @@ mp_obj_t mp_iternext(mp_obj_t o_in) {
mp_raise_TypeError("object not an iterator"); mp_raise_TypeError("object not an iterator");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"'%s' object is not an iterator", mp_obj_get_type_str(o_in))); "'%s' object isn't an iterator", mp_obj_get_type_str(o_in)));
} }
} }
} }

View File

@ -5,5 +5,5 @@ __exit__ None None None
__init__ __init__
__enter__ __enter__
1 1
__exit__ <class 'NameError'> name 'fail' is not defined None __exit__ <class 'NameError'> name 'fail' isn't defined None
NameError NameError

View File

@ -4,4 +4,4 @@ True
False False
Traceback (most recent call last): Traceback (most recent call last):
File "<string>", line 1, in <module> File "<string>", line 1, in <module>
NameError: name 'xyz' is not defined NameError: name 'xyz' isn't defined

View File

@ -5,5 +5,5 @@ __exit__ None None None
__init__ __init__
__enter__ __enter__
1 1
__exit__ <class 'NameError'> name 'fail' is not defined None __exit__ <class 'NameError'> name 'fail' isn't defined None
NameError NameError

View File

@ -50,7 +50,7 @@ except Exception as e:
# Here we have a function with lots of bytecode generated for a single source-line, and # Here we have a function with lots of bytecode generated for a single source-line, and
# there is an error right at the end of the bytecode. It should report the correct line. # there is an error right at the end of the bytecode. It should report the correct line.
def f(): def f():
f([1, 2], [1, 2], [1, 2], {1:1, 1:1, 1:1, 1:1, 1:1, 1:1, 1:X}) f([1, 2], [1, 2], [1, 2], {1:1, 1:1, 1:1, 1:1, 1:1, 1:1, 1:f.X})
return 1 return 1
try: try:
f() f()