summaryrefslogtreecommitdiff
path: root/py/objnamedtuple.c
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2019-01-14 15:14:40 -0800
committerScott Shawcroft <scott@tannewt.org>2019-01-14 17:29:19 -0800
commit72d993d60c5e5238942491df00776ca31f9758a1 (patch)
tree7dc8ff9548dc5c5fe4286414eb361c61b0774306 /py/objnamedtuple.c
parent619bc4caae15ceb7b6de547a5264c9eca9086fe9 (diff)
py changes for supporting superclass constructors that take kwargs
Diffstat (limited to 'py/objnamedtuple.c')
-rw-r--r--py/objnamedtuple.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/py/objnamedtuple.c b/py/objnamedtuple.c
index 800991c43..781a1871b 100644
--- a/py/objnamedtuple.c
+++ b/py/objnamedtuple.c
@@ -93,9 +93,10 @@ void namedtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
}
}
-mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
+mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
const mp_obj_namedtuple_type_t *type = (const mp_obj_namedtuple_type_t*)type_in;
size_t num_fields = type->n_fields;
+ size_t n_kw = kw_args->used;
if (n_args + n_kw != num_fields) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_arg_error_terse_mismatch();
@@ -119,8 +120,8 @@ mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t
// Fill in the remaining slots with the keyword args
memset(&tuple->items[n_args], 0, sizeof(mp_obj_t) * n_kw);
- for (size_t i = n_args; i < n_args + 2 * n_kw; i += 2) {
- qstr kw = mp_obj_str_get_qstr(args[i]);
+ for (size_t i = 0; i < n_kw; i++) {
+ qstr kw = mp_obj_str_get_qstr(kw_args->table[i].key);
size_t id = mp_obj_namedtuple_find_field(type, kw);
if (id == (size_t)-1) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
@@ -138,7 +139,7 @@ mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t
translate("function got multiple values for argument '%q'"), kw);
}
}
- tuple->items[id] = args[i + 1];
+ tuple->items[id] = kw_args->table[i].value;
}
return MP_OBJ_FROM_PTR(tuple);