@@ -125,7 +125,17 @@ static mp_obj_t list_sort(mp_obj_t self_in, mp_obj_t key_fn) {
125125 return mp_const_none ; // return None, as per CPython
126126}
127127
128+ static mp_obj_t list_clear (mp_obj_t self_in ) {
129+ assert (MP_OBJ_IS_TYPE (self_in , & list_type ));
130+ mp_obj_list_t * self = self_in ;
131+ self -> len = 0 ;
132+ self -> items = m_renew (mp_obj_t , self -> items , self -> alloc , 4 );
133+ self -> alloc = 4 ;
134+ return mp_const_none ;
135+ }
136+
128137static MP_DEFINE_CONST_FUN_OBJ_2 (list_append_obj , mp_obj_list_append ) ;
138+ static MP_DEFINE_CONST_FUN_OBJ_1 (list_clear_obj , list_clear ) ;
129139static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (list_pop_obj , 1 , 2 , list_pop ) ;
130140static MP_DEFINE_CONST_FUN_OBJ_2 (list_sort_obj , list_sort ) ;
131141
@@ -140,6 +150,7 @@ const mp_obj_type_t list_type = {
140150 NULL , // iternext
141151 { // method list
142152 { "append" , & list_append_obj },
153+ { "clear" , & list_clear_obj },
143154 { "pop" , & list_pop_obj },
144155 { "sort" , & list_sort_obj },
145156 { NULL , NULL }, // end-of-list sentinel
0 commit comments