3434#include "obj.h"
3535#include "runtime.h"
3636
37- STATIC NORETURN void terse_arg_mismatch (void ) {
38- nlr_raise (mp_obj_new_exception_msg (& mp_type_TypeError , "argument num/types mismatch" ));
39- }
40-
4137void mp_arg_check_num (mp_uint_t n_args , mp_uint_t n_kw , mp_uint_t n_args_min , mp_uint_t n_args_max , bool takes_kw ) {
4238 // TODO maybe take the function name as an argument so we can print nicer error messages
4339
4440 if (n_kw && !takes_kw ) {
4541 if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
46- terse_arg_mismatch ();
42+ mp_arg_error_terse_mismatch ();
4743 } else {
4844 nlr_raise (mp_obj_new_exception_msg (& mp_type_TypeError ,
4945 "function does not take keyword arguments" ));
@@ -53,7 +49,7 @@ void mp_arg_check_num(mp_uint_t n_args, mp_uint_t n_kw, mp_uint_t n_args_min, mp
5349 if (n_args_min == n_args_max ) {
5450 if (n_args != n_args_min ) {
5551 if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
56- terse_arg_mismatch ();
52+ mp_arg_error_terse_mismatch ();
5753 } else {
5854 nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError ,
5955 "function takes %d positional arguments but %d were given" ,
@@ -63,15 +59,15 @@ void mp_arg_check_num(mp_uint_t n_args, mp_uint_t n_kw, mp_uint_t n_args_min, mp
6359 } else {
6460 if (n_args < n_args_min ) {
6561 if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
66- terse_arg_mismatch ();
62+ mp_arg_error_terse_mismatch ();
6763 } else {
6864 nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError ,
6965 "function missing %d required positional arguments" ,
7066 n_args_min - n_args ));
7167 }
7268 } else if (n_args > n_args_max ) {
7369 if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
74- terse_arg_mismatch ();
70+ mp_arg_error_terse_mismatch ();
7571 } else {
7672 nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError ,
7773 "function expected at most %d arguments, got %d" ,
@@ -96,7 +92,7 @@ void mp_arg_parse_all(mp_uint_t n_pos, const mp_obj_t *pos, mp_map_t *kws, mp_ui
9692 if (kw == NULL ) {
9793 if (allowed [i ].flags & MP_ARG_REQUIRED ) {
9894 if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
99- terse_arg_mismatch ();
95+ mp_arg_error_terse_mismatch ();
10096 } else {
10197 nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError ,
10298 "'%s' argument required" ,
@@ -123,7 +119,7 @@ void mp_arg_parse_all(mp_uint_t n_pos, const mp_obj_t *pos, mp_map_t *kws, mp_ui
123119 if (pos_found < n_pos ) {
124120 extra_positional :
125121 if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
126- terse_arg_mismatch ();
122+ mp_arg_error_terse_mismatch ();
127123 } else {
128124 // TODO better error message
129125 nlr_raise (mp_obj_new_exception_msg (& mp_type_TypeError ,
@@ -132,7 +128,7 @@ void mp_arg_parse_all(mp_uint_t n_pos, const mp_obj_t *pos, mp_map_t *kws, mp_ui
132128 }
133129 if (kws_found < kws -> used ) {
134130 if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
135- terse_arg_mismatch ();
131+ mp_arg_error_terse_mismatch ();
136132 } else {
137133 // TODO better error message
138134 nlr_raise (mp_obj_new_exception_msg (& mp_type_TypeError ,
@@ -147,6 +143,12 @@ void mp_arg_parse_all_kw_array(mp_uint_t n_pos, mp_uint_t n_kw, const mp_obj_t *
147143 mp_arg_parse_all (n_pos , args , & kw_args , n_allowed , allowed , out_vals );
148144}
149145
146+ #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
147+ NORETURN void mp_arg_error_terse_mismatch (void ) {
148+ nlr_raise (mp_obj_new_exception_msg (& mp_type_TypeError , "argument num/types mismatch" ));
149+ }
150+ #endif
151+
150152#if MICROPY_CPYTHON_COMPAT
151153NORETURN void mp_arg_error_unimpl_kw (void ) {
152154 nlr_raise (mp_obj_new_exception_msg (& mp_type_NotImplementedError ,
0 commit comments