@@ -121,15 +121,19 @@ STATIC void set_print(void (*print)(void *env, const char *fmt, ...), void *env,
121
121
122
122
123
123
STATIC mp_obj_t set_make_new (mp_obj_t type_in , uint n_args , uint n_kw , const mp_obj_t * args ) {
124
- // TODO check n_kw == 0
124
+ mp_arg_check_num ( n_args , n_kw , 0 , 1 , false);
125
125
126
126
switch (n_args ) {
127
- case 0 :
128
- // return a new, empty set
129
- return mp_obj_new_set (0 , NULL );
127
+ case 0 : {
128
+ // create a new, empty set
129
+ mp_obj_set_t * set = mp_obj_new_set (0 , NULL );
130
+ // set actual set/frozenset type
131
+ set -> base .type = type_in ;
132
+ return set ;
133
+ }
130
134
131
135
case 1 :
132
- {
136
+ default : { // can only be 0 or 1 arg
133
137
// 1 argument, an iterable from which we make a new set
134
138
mp_obj_set_t * set = mp_obj_new_set (0 , NULL );
135
139
mp_obj_t iterable = mp_getiter (args [0 ]);
@@ -141,9 +145,6 @@ STATIC mp_obj_t set_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_
141
145
set -> base .type = type_in ;
142
146
return set ;
143
147
}
144
-
145
- default :
146
- nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError , "set takes at most 1 argument, %d given" , n_args ));
147
148
}
148
149
}
149
150
0 commit comments