Skip to content

Commit 44cd46a

Browse files
committed
objnamedtuple: Accept field list as a string.
This change is required to unbreak some CPython stdlib modules (as included into micropython-lib).
1 parent 8705171 commit 44cd46a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

py/objnamedtuple.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "py/nlr.h"
3131
#include "py/objtuple.h"
3232
#include "py/runtime.h"
33+
#include "py/objstr.h"
3334

3435
#if MICROPY_PY_COLLECTIONS
3536

@@ -169,6 +170,11 @@ STATIC mp_obj_t new_namedtuple_type(mp_obj_t name_in, mp_obj_t fields_in) {
169170
qstr name = mp_obj_str_get_qstr(name_in);
170171
mp_uint_t n_fields;
171172
mp_obj_t *fields;
173+
#if MICROPY_CPYTHON_COMPAT
174+
if (MP_OBJ_IS_STR(fields_in)) {
175+
fields_in = mp_obj_str_split(1, &fields_in);
176+
}
177+
#endif
172178
if (!MP_OBJ_IS_TYPE(fields_in, &mp_type_list)) {
173179
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "list required"));
174180
}

0 commit comments

Comments
 (0)