diff --git a/py/objstr.c b/py/objstr.c index 67de2ce80413f39bfe62cc23f1ee6a85e11b82ee..4ec1034e1e681a815fa521652c53a3a91a4d3d03 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -355,9 +355,6 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { if (!mp_seq_get_fast_slice_indexes(self_len, index, &start, &stop)) { assert(0); } - if (start >= stop) { - return MP_OBJ_NEW_QSTR(MP_QSTR_); - } return str_new(type, self_data + start, stop - start); } #endif diff --git a/py/sequence.c b/py/sequence.c index 2c1f6a836c8a5613a0f6a36822f12687ffd94f25..0a4bb26b31486c50f7e4fad79a6320a3b7d077f8 100644 --- a/py/sequence.c +++ b/py/sequence.c @@ -88,6 +88,12 @@ bool mp_seq_get_fast_slice_indexes(machine_uint_t len, mp_obj_t slice, machine_u } else if (stop > len) { stop = len; } + + // CPython returns empty sequence in such case, or point for assignment is at start + if (start > stop) { + stop = start; + } + *begin = start; *end = stop; return true;