34
34
#include "obj.h"
35
35
#include "runtime.h"
36
36
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
-
41
37
void 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 ) {
42
38
// TODO maybe take the function name as an argument so we can print nicer error messages
43
39
44
40
if (n_kw && !takes_kw ) {
45
41
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
46
- terse_arg_mismatch ();
42
+ mp_arg_error_terse_mismatch ();
47
43
} else {
48
44
nlr_raise (mp_obj_new_exception_msg (& mp_type_TypeError ,
49
45
"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
53
49
if (n_args_min == n_args_max ) {
54
50
if (n_args != n_args_min ) {
55
51
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
56
- terse_arg_mismatch ();
52
+ mp_arg_error_terse_mismatch ();
57
53
} else {
58
54
nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError ,
59
55
"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
63
59
} else {
64
60
if (n_args < n_args_min ) {
65
61
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
66
- terse_arg_mismatch ();
62
+ mp_arg_error_terse_mismatch ();
67
63
} else {
68
64
nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError ,
69
65
"function missing %d required positional arguments" ,
70
66
n_args_min - n_args ));
71
67
}
72
68
} else if (n_args > n_args_max ) {
73
69
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
74
- terse_arg_mismatch ();
70
+ mp_arg_error_terse_mismatch ();
75
71
} else {
76
72
nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError ,
77
73
"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
96
92
if (kw == NULL ) {
97
93
if (allowed [i ].flags & MP_ARG_REQUIRED ) {
98
94
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
99
- terse_arg_mismatch ();
95
+ mp_arg_error_terse_mismatch ();
100
96
} else {
101
97
nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError ,
102
98
"'%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
123
119
if (pos_found < n_pos ) {
124
120
extra_positional :
125
121
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
126
- terse_arg_mismatch ();
122
+ mp_arg_error_terse_mismatch ();
127
123
} else {
128
124
// TODO better error message
129
125
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
132
128
}
133
129
if (kws_found < kws -> used ) {
134
130
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
135
- terse_arg_mismatch ();
131
+ mp_arg_error_terse_mismatch ();
136
132
} else {
137
133
// TODO better error message
138
134
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 *
147
143
mp_arg_parse_all (n_pos , args , & kw_args , n_allowed , allowed , out_vals );
148
144
}
149
145
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
+
150
152
#if MICROPY_CPYTHON_COMPAT
151
153
NORETURN void mp_arg_error_unimpl_kw (void ) {
152
154
nlr_raise (mp_obj_new_exception_msg (& mp_type_NotImplementedError ,
0 commit comments