Skip to content

Commit ea85a12

Browse files
committed
objdict: Support creating dict from another dict.
1 parent cdd96df commit ea85a12

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

py/objdict.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
STATIC mp_obj_t mp_obj_new_dict_iterator(mp_obj_dict_t *dict, int cur);
1414
STATIC mp_map_elem_t *dict_it_iternext_elem(mp_obj_t self_in);
15+
STATIC mp_obj_t dict_copy(mp_obj_t self_in);
1516

1617
STATIC void dict_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
1718
mp_obj_dict_t *self = self_in;
@@ -39,6 +40,10 @@ STATIC mp_obj_t dict_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp
3940
break;
4041

4142
case 1:
43+
if (MP_OBJ_IS_TYPE(args[0], &mp_type_dict)) {
44+
return dict_copy(args[0]);
45+
}
46+
// TODO create dict from an arbitrary mapping!
4247
// TODO create dict from an iterable!
4348
assert(false);
4449

0 commit comments

Comments
 (0)