Skip to content

Commit 3fd2d7f

Browse files
committed
py: Tidy up function argument error messages.
We are not as verbose as CPython, and maybe a bit too cryptic sometimes.
1 parent 32ca164 commit 3fd2d7f

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

py/objfun.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,27 @@ STATIC void check_nargs(mp_obj_fun_native_t *self, int n_args, int n_kw) {
3030
}
3131

3232
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) {
33+
// TODO maybe take the function name as an argument so we can print nicer error messages
34+
3335
if (n_kw && !is_kw) {
34-
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
35-
"function does not take keyword arguments"));
36+
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "function does not take keyword arguments"));
3637
}
3738

3839
if (n_args_min == n_args_max) {
3940
if (n_args != n_args_min) {
4041
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
41-
"function takes %d positional arguments but %d were given",
42-
n_args_min, n_args));
42+
"function takes %d positional arguments but %d were given",
43+
n_args_min, n_args));
4344
}
4445
} else {
4546
if (n_args < n_args_min) {
4647
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
47-
"<fun name>() missing %d required positional arguments: <list of names of params>",
48+
"function missing %d required positional arguments",
4849
n_args_min - n_args));
4950
} else if (n_args > n_args_max) {
5051
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
51-
"<fun name> expected at most %d arguments, got %d",
52-
n_args_max, n_args));
52+
"function expected at most %d arguments, got %d",
53+
n_args_max, n_args));
5354
}
5455
}
5556
}

0 commit comments

Comments
 (0)