From 44cd46a7e4e8a2b7666f6fe356adfe19daa6b1e6 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 23 Mar 2015 22:44:16 +0200 Subject: [PATCH] objnamedtuple: Accept field list as a string. This change is required to unbreak some CPython stdlib modules (as included into micropython-lib). --- py/objnamedtuple.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/py/objnamedtuple.c b/py/objnamedtuple.c index 4bb0c0ae00..1996b41219 100644 --- a/py/objnamedtuple.c +++ b/py/objnamedtuple.c @@ -30,6 +30,7 @@ #include "py/nlr.h" #include "py/objtuple.h" #include "py/runtime.h" +#include "py/objstr.h" #if MICROPY_PY_COLLECTIONS @@ -169,6 +170,11 @@ STATIC mp_obj_t new_namedtuple_type(mp_obj_t name_in, mp_obj_t fields_in) { qstr name = mp_obj_str_get_qstr(name_in); mp_uint_t n_fields; mp_obj_t *fields; + #if MICROPY_CPYTHON_COMPAT + if (MP_OBJ_IS_STR(fields_in)) { + fields_in = mp_obj_str_split(1, &fields_in); + } + #endif if (!MP_OBJ_IS_TYPE(fields_in, &mp_type_list)) { nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "list required")); }