summaryrefslogtreecommitdiff
path: root/py/objtuple.c
diff options
context:
space:
mode:
authorRoy Hooper <rhooper@toybox.ca>2020-01-11 17:37:37 -0500
committerRoy Hooper <rhooper@toybox.ca>2020-01-11 18:21:43 -0500
commit73e076a40cc82f1dab83791b2efc547265ae0b92 (patch)
tree84aa5265268f02343c7895be6367378b4d6694e8 /py/objtuple.c
parent2cb8f7b2df2583c9fdb545744adad2386b4ee7f3 (diff)
make types that depend on tuple subscr work
Diffstat (limited to 'py/objtuple.c')
-rw-r--r--py/objtuple.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/py/objtuple.c b/py/objtuple.c
index 2b483f8b8..0a2ed6f4c 100644
--- a/py/objtuple.c
+++ b/py/objtuple.c
@@ -29,6 +29,7 @@
#include "py/objtuple.h"
#include "py/runtime.h"
+#include "py/objtype.h"
#include "supervisor/shared/translate.h"
@@ -178,10 +179,14 @@ mp_obj_t mp_obj_tuple_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) {
}
mp_obj_t mp_obj_tuple_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
-
if (value == MP_OBJ_SENTINEL) {
// load
mp_obj_tuple_t *self = MP_OBJ_TO_PTR(self_in);
+ // when called with a native type (eg namedtuple) using mp_obj_tuple_subscr, get the native self
+ if (self->base.type->subscr != &mp_obj_tuple_subscr) {
+ self = mp_instance_cast_to_native_base(self_in, &mp_type_tuple);
+ }
+
#if MICROPY_PY_BUILTINS_SLICE
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
mp_bound_slice_t slice;