objnamedtuple: Support iteration.
This commit is contained in:
parent
3793830ed9
commit
7067d69bcc
@ -160,6 +160,7 @@ mp_obj_t mp_obj_new_namedtuple_type(qstr name, const char *fields) {
|
|||||||
o->base.load_attr = namedtuple_load_attr;
|
o->base.load_attr = namedtuple_load_attr;
|
||||||
o->base.store_attr = namedtuple_store_attr;
|
o->base.store_attr = namedtuple_store_attr;
|
||||||
o->base.subscr = tuple_subscr;
|
o->base.subscr = tuple_subscr;
|
||||||
|
o->base.getiter = tuple_getiter;
|
||||||
o->base.bases_tuple = (mp_obj_t)&namedtuple_base_tuple;
|
o->base.bases_tuple = (mp_obj_t)&namedtuple_base_tuple;
|
||||||
o->fields = fields;
|
o->fields = fields;
|
||||||
return o;
|
return o;
|
||||||
|
@ -174,7 +174,7 @@ mp_obj_t tuple_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC mp_obj_t tuple_getiter(mp_obj_t o_in) {
|
mp_obj_t tuple_getiter(mp_obj_t o_in) {
|
||||||
return mp_obj_new_tuple_iterator(o_in, 0);
|
return mp_obj_new_tuple_iterator(o_in, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,3 +34,4 @@ void tuple_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_o
|
|||||||
mp_obj_t tuple_unary_op(int op, mp_obj_t self_in);
|
mp_obj_t tuple_unary_op(int op, mp_obj_t self_in);
|
||||||
mp_obj_t tuple_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs);
|
mp_obj_t tuple_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs);
|
||||||
mp_obj_t tuple_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value);
|
mp_obj_t tuple_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value);
|
||||||
|
mp_obj_t tuple_getiter(mp_obj_t o_in);
|
||||||
|
@ -16,6 +16,8 @@ print(bool(t))
|
|||||||
print(t + t)
|
print(t + t)
|
||||||
print(t * 3)
|
print(t * 3)
|
||||||
|
|
||||||
|
print([f for f in t])
|
||||||
|
|
||||||
print(isinstance(t, tuple))
|
print(isinstance(t, tuple))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user