From 84e0cf0d215d1248a6f2c4dc977c5702f317fe06 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 1 Jan 2015 15:43:25 +0000 Subject: [PATCH] py: Change namedtuple error messages to reduce code size. We are not word-for-word compatible with CPython exceptions, so we are free to make them short but informative in order to reduce code size. Also, try to make messages the same as existing ones where possible. --- py/objnamedtuple.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/py/objnamedtuple.c b/py/objnamedtuple.c index d9ceea817e..c0510081c3 100644 --- a/py/objnamedtuple.c +++ b/py/objnamedtuple.c @@ -89,11 +89,14 @@ STATIC mp_obj_t namedtuple_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_ if (n_args + n_kw != num_fields) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { mp_arg_error_terse_mismatch(); - } else { - // Counts include implicit "self" + } else if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, - "__new__() takes %d positional arguments but %d were given", - num_fields + 1, n_args + n_kw + 1)); + "function takes %d positional arguments but %d were given", + num_fields, n_args + n_kw)); + } else if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED) { + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, + "%s() takes %d positional arguments but %d were given", + qstr_str(type->base.name), num_fields, n_args + n_kw)); } } @@ -117,7 +120,7 @@ STATIC mp_obj_t namedtuple_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_ mp_arg_error_terse_mismatch(); } else { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, - "__new__() got an unexpected keyword argument '%s'", + "unexpected keyword argument '%s'", qstr_str(kw))); } } @@ -126,7 +129,7 @@ STATIC mp_obj_t namedtuple_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_ mp_arg_error_terse_mismatch(); } else { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, - "__new__() got multiple values for argument '%s'", + "function got multiple values for argument '%s'", qstr_str(kw))); } }