Skip to content
Snippets Groups Projects
Commit 7e652af2 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

array: CPython prints empty arrays inconsistently (only typecode, no []).

parent 0dd0467a
No related branches found
No related tags found
No related merge requests found
...@@ -124,17 +124,21 @@ static void array_set_el(mp_obj_array_t *o, int index, mp_obj_t val_in) { ...@@ -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) { 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; mp_obj_array_t *o = o_in;
if (o->typecode == BYTEARRAY_TYPECODE) { if (o->typecode == BYTEARRAY_TYPECODE) {
print(env, "bytearray([", o->typecode); print(env, "bytearray(", o->typecode);
} else { } else {
print(env, "array('%c', [", o->typecode); print(env, "array('%c'", o->typecode);
} }
if (o->len > 0) {
print(env, ", [", o->typecode);
for (int i = 0; i < o->len; i++) { for (int i = 0; i < o->len; i++) {
if (i > 0) { if (i > 0) {
print(env, ", "); 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) { static mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment