@@ -121,15 +121,19 @@ STATIC void set_print(void (*print)(void *env, const char *fmt, ...), void *env,
121121
122122
123123STATIC 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);
125125
126126 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+ }
130134
131135 case 1 :
132- {
136+ default : { // can only be 0 or 1 arg
133137 // 1 argument, an iterable from which we make a new set
134138 mp_obj_set_t * set = mp_obj_new_set (0 , NULL );
135139 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_
141145 set -> base .type = type_in ;
142146 return set ;
143147 }
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 ));
147148 }
148149}
149150
0 commit comments