diff options
author | Damien George <damien.p.george@gmail.com> | 2015-01-01 15:33:50 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-01-01 15:33:50 +0000 |
commit | 7f23384d4920f7d1a4ea743a51a2d54fd0889e72 (patch) | |
tree | f6f46cda8f8173e329a6a53b67358d5203b521a4 /py/objnamedtuple.c | |
parent | 276159e5ddedfdb863bf34e4ae25c58621af5750 (diff) | |
download | micropython-7f23384d4920f7d1a4ea743a51a2d54fd0889e72.tar.gz micropython-7f23384d4920f7d1a4ea743a51a2d54fd0889e72.zip |
py: Make terse_arg_mismatch a global function and use it elsewhere.
Reduces code size when MICROPY_ERROR_REPORTING_TERSE is selected.
Diffstat (limited to 'py/objnamedtuple.c')
-rw-r--r-- | py/objnamedtuple.c | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/py/objnamedtuple.c b/py/objnamedtuple.c index fc5f03c8f6..d9ceea817e 100644 --- a/py/objnamedtuple.c +++ b/py/objnamedtuple.c @@ -33,6 +33,7 @@ #include "qstr.h" #include "obj.h" #include "objtuple.h" +#include "runtime.h" #if MICROPY_PY_COLLECTIONS @@ -86,10 +87,14 @@ STATIC mp_obj_t namedtuple_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_ mp_obj_namedtuple_type_t *type = type_in; mp_uint_t num_fields = type->n_fields; if (n_args + n_kw != num_fields) { - // Counts include implicit "self" - 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)); + if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { + mp_arg_error_terse_mismatch(); + } else { + // Counts include implicit "self" + 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)); + } } mp_obj_t *arg_objects; @@ -108,14 +113,22 @@ STATIC mp_obj_t namedtuple_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_ qstr kw = MP_OBJ_QSTR_VALUE(args[i]); int id = namedtuple_find_field(type, kw); if (id == -1) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, - "__new__() got an unexpected keyword argument '%s'", - qstr_str(kw))); + if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { + mp_arg_error_terse_mismatch(); + } else { + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, + "__new__() got an unexpected keyword argument '%s'", + qstr_str(kw))); + } } if (arg_objects[id] != NULL) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, - "__new__() got multiple values for argument '%s'", - qstr_str(kw))); + if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { + mp_arg_error_terse_mismatch(); + } else { + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, + "__new__() got multiple values for argument '%s'", + qstr_str(kw))); + } } arg_objects[id] = args[i + 1]; } |