time: Allow constructing a struct_time from another struct_time

This commit is contained in:
Jeff Epler 2021-06-26 20:01:19 -05:00
parent 05aa8ea404
commit 9449a35405
1 changed files with 4 additions and 6 deletions

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)) {
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) {
mp_raise_TypeError(translate("time.struct_time() takes a 9-sequence"));
}
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(args[0]);
return namedtuple_make_new(type, 9, tuple->items, NULL);
size_t len;
mp_obj_t *items;
mp_obj_get_array(args[0], &len, &items);
return namedtuple_make_new(type, len, items, NULL);
}
//| class struct_time: