diff options
author | Damien George <damien.p.george@gmail.com> | 2015-01-01 15:43:25 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-01-01 15:43:25 +0000 |
commit | 84e0cf0d215d1248a6f2c4dc977c5702f317fe06 (patch) | |
tree | d2a532ddee4d72b77131fada248a13adfb1f5198 | |
parent | 7f23384d4920f7d1a4ea743a51a2d54fd0889e72 (diff) | |
download | micropython-84e0cf0d215d1248a6f2c4dc977c5702f317fe06.tar.gz micropython-84e0cf0d215d1248a6f2c4dc977c5702f317fe06.zip |
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.
-rw-r--r-- | py/objnamedtuple.c | 15 |
1 files 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))); } } |