diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-01-28 03:14:20 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-01-28 03:19:13 +0200 |
commit | 7e652af242ca7afaafd611252fc33bc5682a6680 (patch) | |
tree | 0ae3ffce2b6acbb1cfe7b246f3126e99a314c86b | |
parent | 0dd0467a977f5c133b27aba2d2562ea9e8635115 (diff) | |
download | micropython-7e652af242ca7afaafd611252fc33bc5682a6680.tar.gz micropython-7e652af242ca7afaafd611252fc33bc5682a6680.zip |
array: CPython prints empty arrays inconsistently (only typecode, no []).
-rw-r--r-- | py/objarray.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/py/objarray.c b/py/objarray.c index 88f7888112..ef5fe8ffef 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -124,17 +124,21 @@ static void array_set_el(mp_obj_array_t *o, int index, mp_obj_t val_in) { static void array_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) { mp_obj_array_t *o = o_in; if (o->typecode == BYTEARRAY_TYPECODE) { - print(env, "bytearray([", o->typecode); + print(env, "bytearray(", o->typecode); } else { - print(env, "array('%c', [", o->typecode); + print(env, "array('%c'", o->typecode); } - for (int i = 0; i < o->len; i++) { - if (i > 0) { - print(env, ", "); + if (o->len > 0) { + print(env, ", [", o->typecode); + for (int i = 0; i < o->len; i++) { + if (i > 0) { + print(env, ", "); + } + print(env, "%d", array_get_el(o, i)); } - print(env, "%d", array_get_el(o, i)); + print(env, "]"); } - print(env, "])"); + print(env, ")"); } static mp_obj_t array_construct(char typecode, mp_obj_t initializer) { |