@@ -981,8 +981,14 @@ const mp_obj_type_t mp_type_type = {
981981};
982982
983983mp_obj_t mp_obj_new_type (qstr name , mp_obj_t bases_tuple , mp_obj_t locals_dict ) {
984- assert (MP_OBJ_IS_TYPE (bases_tuple , & mp_type_tuple )); // MicroPython restriction, for now
985- assert (MP_OBJ_IS_TYPE (locals_dict , & mp_type_dict )); // MicroPython restriction, for now
984+ if (!MP_OBJ_IS_TYPE (bases_tuple , & mp_type_tuple )) {
985+ // MicroPython restriction, for now
986+ mp_raise_TypeError ("type() argument 2 must be tuple" );
987+ }
988+ if (!MP_OBJ_IS_TYPE (locals_dict , & mp_type_dict )) {
989+ // MicroPython restriction, for now
990+ mp_raise_TypeError ("type() argument 3 must be dict" );
991+ }
986992
987993 // TODO might need to make a copy of locals_dict; at least that's how CPython does it
988994
@@ -991,7 +997,9 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
991997 mp_obj_t * items ;
992998 mp_obj_tuple_get (bases_tuple , & len , & items );
993999 for (size_t i = 0 ; i < len ; i ++ ) {
994- assert (MP_OBJ_IS_TYPE (items [i ], & mp_type_type ));
1000+ if (!MP_OBJ_IS_TYPE (items [i ], & mp_type_type )) {
1001+ mp_raise_TypeError ("type is not an acceptable base type" );
1002+ }
9951003 mp_obj_type_t * t = MP_OBJ_TO_PTR (items [i ]);
9961004 // TODO: Verify with CPy, tested on function type
9971005 if (t -> make_new == NULL ) {
@@ -1077,6 +1085,9 @@ STATIC mp_obj_t super_make_new(const mp_obj_type_t *type_in, size_t n_args, size
10771085 // 0 arguments are turned into 2 in the compiler
10781086 // 1 argument is not yet implemented
10791087 mp_arg_check_num (n_args , n_kw , 2 , 2 , false);
1088+ if (!MP_OBJ_IS_TYPE (args [0 ], & mp_type_type )) {
1089+ mp_raise_TypeError ("first argument to super() must be type" );
1090+ }
10801091 mp_obj_super_t * o = m_new_obj (mp_obj_super_t );
10811092 * o = (mp_obj_super_t ){{type_in }, args [0 ], args [1 ]};
10821093 return MP_OBJ_FROM_PTR (o );
0 commit comments