Skip to content

Commit 1a37588

Browse files
committed
py: Provide more details for too few and too much args for Python fun calls.
1 parent 48fdaad commit 1a37588

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

py/objfun.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ STATIC mp_obj_t fun_bc_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_o
229229
if (n_args > self->n_args) {
230230
// given more than enough arguments
231231
if (!self->takes_var_args) {
232-
goto arg_error;
232+
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
233+
"function takes %d positional arguments but %d were given", self->n_args, n_args));
233234
}
234235
// put extra arguments in varargs tuple
235236
*extra_args = mp_obj_new_tuple(n_args - self->n_args, args + self->n_args);
@@ -249,7 +250,9 @@ STATIC mp_obj_t fun_bc_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_o
249250
extra_args -= self->n_args - n_args;
250251
n_extra_args += self->n_args - n_args;
251252
} else {
252-
goto arg_error;
253+
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
254+
"function takes at least %d positional arguments but %d were given",
255+
self->n_args - self->n_def_args, n_args));
253256
}
254257
}
255258
}
@@ -344,9 +347,6 @@ continue2:;
344347
} else { // MP_VM_RETURN_EXCEPTION
345348
nlr_raise(result);
346349
}
347-
348-
arg_error:
349-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "function takes %d positional arguments but %d were given", self->n_args, n_args));
350350
}
351351

352352
const mp_obj_type_t mp_type_fun_bc = {

0 commit comments

Comments
 (0)