mirror of
https://github.com/micropython/micropython.git
synced 2026-01-08 05:00:26 +01:00
Merge pull request #191 from pfalcon/store-item
Add store_item() virtual method to type to implement container[index] = val
This commit is contained in:
10
py/runtime.c
10
py/runtime.c
@@ -879,7 +879,15 @@ void rt_store_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
|
||||
// dict store
|
||||
mp_obj_dict_store(base, index, value);
|
||||
} else {
|
||||
assert(0);
|
||||
mp_obj_type_t *type = mp_obj_get_type(base);
|
||||
if (type->store_item != NULL) {
|
||||
bool r = type->store_item(base, index, value);
|
||||
if (r) {
|
||||
return;
|
||||
}
|
||||
// TODO: call base classes here?
|
||||
}
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "'%s' object does not support item assignment", mp_obj_get_type_str(base)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user