@@ -212,10 +212,10 @@ static void class_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
212212 // TODO check that this is the correct place to have this logic
213213 if (MP_OBJ_IS_TYPE (member , & mp_type_staticmethod )) {
214214 // return just the function
215- dest [0 ] = ((mp_obj_staticmethod_t * )member )-> fun ;
215+ dest [0 ] = ((mp_obj_static_class_method_t * )member )-> fun ;
216216 } else if (MP_OBJ_IS_TYPE (member , & mp_type_classmethod )) {
217217 // return a bound method, with self being the type of this object
218- dest [0 ] = ((mp_obj_classmethod_t * )member )-> fun ;
218+ dest [0 ] = ((mp_obj_static_class_method_t * )member )-> fun ;
219219 dest [1 ] = mp_obj_get_type (self_in );
220220 } else {
221221 // return a bound method, with self being this object
@@ -304,10 +304,10 @@ static void type_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
304304 // see http://docs.python.org/3.3/howto/descriptor.html
305305 if (MP_OBJ_IS_TYPE (member , & mp_type_staticmethod )) {
306306 // return just the function
307- dest [0 ] = ((mp_obj_staticmethod_t * )member )-> fun ;
307+ dest [0 ] = ((mp_obj_static_class_method_t * )member )-> fun ;
308308 } else if (MP_OBJ_IS_TYPE (member , & mp_type_classmethod )) {
309309 // return a bound method, with self being this class
310- dest [0 ] = ((mp_obj_classmethod_t * )member )-> fun ;
310+ dest [0 ] = ((mp_obj_static_class_method_t * )member )-> fun ;
311311 dest [1 ] = self_in ;
312312 } else {
313313 // return just the function
@@ -417,10 +417,10 @@ static void super_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
417417 // TODO check that this is the correct place to have this logic
418418 if (MP_OBJ_IS_TYPE (member , & mp_type_staticmethod )) {
419419 // return just the function
420- dest [0 ] = ((mp_obj_staticmethod_t * )member )-> fun ;
420+ dest [0 ] = ((mp_obj_static_class_method_t * )member )-> fun ;
421421 } else if (MP_OBJ_IS_TYPE (member , & mp_type_classmethod )) {
422422 // return a bound method, with self being the type of this object
423- dest [0 ] = ((mp_obj_classmethod_t * )member )-> fun ;
423+ dest [0 ] = ((mp_obj_static_class_method_t * )member )-> fun ;
424424 dest [1 ] = mp_obj_get_type (self -> obj );
425425 } else {
426426 // return a bound method, with self being this object
@@ -507,12 +507,26 @@ MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_isinstance_obj, mp_builtin_isinstance);
507507/******************************************************************************/
508508// staticmethod and classmethod types (probably should go in a different file)
509509
510+ static mp_obj_t static_class_method_make_new (mp_obj_t self_in , uint n_args , uint n_kw , const mp_obj_t * args ) {
511+ assert (self_in == & mp_type_staticmethod || self_in == & mp_type_classmethod );
512+
513+ if (n_args != 1 || n_kw != 0 ) {
514+ nlr_jump (mp_obj_new_exception_msg_1_arg (MP_QSTR_TypeError , "function takes 1 positional argument but %d were given" , (void * )(machine_int_t )n_args ));
515+ }
516+
517+ mp_obj_static_class_method_t * o = m_new_obj (mp_obj_static_class_method_t );
518+ * o = (mp_obj_static_class_method_t ){{(mp_obj_type_t * )self_in }, args [0 ]};
519+ return o ;
520+ }
521+
510522const mp_obj_type_t mp_type_staticmethod = {
511523 { & mp_const_type },
512524 "staticmethod" ,
525+ .make_new = static_class_method_make_new
513526};
514527
515528const mp_obj_type_t mp_type_classmethod = {
516529 { & mp_const_type },
517530 "classmethod" ,
531+ .make_new = static_class_method_make_new
518532};
0 commit comments