time: Allow constructing a struct_time from another struct_time

Closes: #4917
This commit is contained in:
Jeff Epler 2021-06-26 20:01:19 -05:00
parent 33482e0831
commit cac71a33fc

View File

@ -83,12 +83,10 @@ mp_obj_t struct_time_make_new(const mp_obj_type_t *type, size_t n_args, const mp
if (n_args != 1 || (kw_args != NULL && kw_args->used > 0)) { if (n_args != 1 || (kw_args != NULL && kw_args->used > 0)) {
return namedtuple_make_new(type, n_args, args, kw_args); return namedtuple_make_new(type, n_args, args, kw_args);
} }
if (mp_obj_get_type(args[0])->getiter != mp_obj_tuple_getiter || ((mp_obj_tuple_t *)MP_OBJ_TO_PTR(args[0]))->len != 9) { size_t len;
mp_raise_TypeError(translate("time.struct_time() takes a 9-sequence")); mp_obj_t *items;
} mp_obj_get_array(args[0], &len, &items);
return namedtuple_make_new(type, len, items, NULL);
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(args[0]);
return namedtuple_make_new(type, 9, tuple->items, NULL);
} }
//| class struct_time: //| class struct_time: