diff options
author | Damien George <damien.p.george@gmail.com> | 2014-04-18 22:06:55 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-04-18 22:06:55 +0100 |
commit | 3fd2d7fad2022e3f26304fbc6ad74e6d8dd66e5f (patch) | |
tree | ff8a31890dd2ce99c29801c9d3762bdbbad48129 /py/objfun.c | |
parent | 32ca16499214ed80e490d27ad2dd90287520938b (diff) | |
download | micropython-3fd2d7fad2022e3f26304fbc6ad74e6d8dd66e5f.tar.gz micropython-3fd2d7fad2022e3f26304fbc6ad74e6d8dd66e5f.zip |
py: Tidy up function argument error messages.
We are not as verbose as CPython, and maybe a bit too cryptic sometimes.
Diffstat (limited to 'py/objfun.c')
-rw-r--r-- | py/objfun.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/py/objfun.c b/py/objfun.c index 07d6606c53..c9d40e55a3 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -30,26 +30,27 @@ STATIC void check_nargs(mp_obj_fun_native_t *self, int n_args, int n_kw) { } void mp_check_nargs(int n_args, machine_uint_t n_args_min, machine_uint_t n_args_max, int n_kw, bool is_kw) { + // TODO maybe take the function name as an argument so we can print nicer error messages + if (n_kw && !is_kw) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, - "function does not take keyword arguments")); + nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "function does not take keyword arguments")); } if (n_args_min == n_args_max) { if (n_args != n_args_min) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, - "function takes %d positional arguments but %d were given", - n_args_min, n_args)); + "function takes %d positional arguments but %d were given", + n_args_min, n_args)); } } else { if (n_args < n_args_min) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, - "<fun name>() missing %d required positional arguments: <list of names of params>", + "function missing %d required positional arguments", n_args_min - n_args)); } else if (n_args > n_args_max) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, - "<fun name> expected at most %d arguments, got %d", - n_args_max, n_args)); + "function expected at most %d arguments, got %d", + n_args_max, n_args)); } } } |