Skip to content

Commit 69d081a

Browse files
committed
py: Handle case of slice start > stop in common sequence function.
1 parent afaaf53 commit 69d081a

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

py/objstr.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,6 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
355355
if (!mp_seq_get_fast_slice_indexes(self_len, index, &start, &stop)) {
356356
assert(0);
357357
}
358-
if (start >= stop) {
359-
return MP_OBJ_NEW_QSTR(MP_QSTR_);
360-
}
361358
return str_new(type, self_data + start, stop - start);
362359
}
363360
#endif

py/sequence.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ bool mp_seq_get_fast_slice_indexes(machine_uint_t len, mp_obj_t slice, machine_u
8888
} else if (stop > len) {
8989
stop = len;
9090
}
91+
92+
// CPython returns empty sequence in such case, or point for assignment is at start
93+
if (start > stop) {
94+
stop = start;
95+
}
96+
9197
*begin = start;
9298
*end = stop;
9399
return true;

0 commit comments

Comments
 (0)