8000 Merge remote-tracking branch 'origin/main' into main · domdfcoding/circuitpython@e7d3c5e · GitHub
[go: up one dir, main page]

Skip to content

Commit e7d3c5e

Browse files
committed
Merge remote-tracking branch 'origin/main' into main
2 parents b6c8098 + 7f39779 commit e7d3c5e

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

py/obj.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
444444

445445
// note: returned value in *items may point to the interior of a GC block
446446
void mp_obj_get_array(mp_obj_t o, size_t *len, mp_obj_t **items) {
447-
if (mp_obj_is_type(o, &mp_type_tuple)) {
447+
if (mp_obj_is_tuple_compatible(o)) {
448448
mp_obj_tuple_get(o, len, items);
449449
} else if (mp_obj_is_type(o, &mp_type_list)) {
450450
mp_obj_list_get(o, len, items);

py/obj.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ extern const struct _mp_obj_exception_t mp_const_GeneratorExit_obj;
764764
#define mp_obj_is_str_or_bytes(o) (mp_obj_is_qstr(o) || (mp_obj_is_obj(o) && ((mp_obj_base_t *)MP_OBJ_TO_PTR(o))->type->binary_op == mp_obj_str_binary_op))
765765
#define mp_obj_is_dict_or_ordereddict(o) (mp_obj_is_obj(o) && ((mp_obj_base_t *)MP_OBJ_TO_PTR(o))->type->make_new == mp_obj_dict_make_new)
766766
#define mp_obj_is_fun(o) (mp_obj_is_obj(o) && (((mp_obj_base_t *)MP_OBJ_TO_PTR(o))->type->name == MP_QSTR_function))
767+
// type check is done on getiter method to allow tuple, namedtuple, attrtuple
768+
#define mp_obj_is_tuple_compatible(o) (mp_obj_get_type(o)->getiter == mp_obj_tuple_getiter)
767769

768770
mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict);
769771
static inline mp_obj_t mp_obj_new_bool(mp_int_t x) {

py/objtuple.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434

3535
#include "supervisor/shared/translate.h"
3636

37-
// type check is done on getiter method to allow tuple, namedtuple, attrtuple
38-
#define mp_obj_is_tuple_compatible(o) (mp_obj_get_type(o)->getiter == mp_obj_tuple_getiter)
3937

4038
/******************************************************************************/
4139
/* tuple */

shared-bindings/time/__init__.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,21 @@ MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_obj, time_sleep);
8080

8181
#if MICROPY_PY_COLLECTIONS
8282
mp_obj_t struct_time_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
83-
if (n_args != 1 || (kw_args != NULL && kw_args->used > 0)) {
84-
return namedtuple_make_new(type, n_args, args, kw_args);
85-
}
86-
if (mp_obj_get_type(args[0])->getiter != mp_obj_tuple_getiter || ((mp_obj_tuple_t *)MP_OBJ_TO_PTR(args[0]))->len != 9) {
83+
mp_arg_check_num(n_args, kw_args, 1, 1, false);
84+
size_t len;
85+
mp_obj_t *items;
86+
mp_obj_get_array(args[0], &len, &items);
87+
if (len != 9) {
8788
mp_raise_TypeError(translate("time.struct_time() takes a 9-sequence"));
8889
}
89-
90-
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(args[0]);
91-
return namedtuple_make_new(type, 9, tuple->items, NULL);
90+
return namedtuple_make_new(type, len, items, NULL);
9291
}
9392

9493
//| class struct_time:
95-
//| def __init__(self, time_tuple: Tuple[int, int, int, int, int, int, int, int, int]) -> None:
96-
//| """Structure used to capture a date and time. Note that it takes a tuple!
94+
//| def __init__(self, time_tuple: Sequence[int]) -> None:
95+
//| """Structure used to capture a date and time. Can be constructed from a `struct_time`, `tuple`, `list`, or `namedtuple` with 9 elements.
9796
//|
98-
//| :param tuple time_tuple: Tuple of time info: ``(tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst)``
97+
//| :param Sequence time_tuple: Sequence of time info: ``(tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst)``
9998
//|
10099
//| * ``tm_year``: the year, 2017 for example
101100
//| * ``tm_mon``: the month, range [1, 12]

0 commit comments

Comments
 (0)
0