Skip to content

Commit 03659c5

Browse files
committed
py/objrange: Fix slicing of range when step of slice is negative.
1 parent e1b0f2a commit 03659c5

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

py/objrange.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ STATIC mp_obj_t range_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
154154
o->start = self->start + slice.start * self->step;
155155
o->stop = self->start + slice.stop * self->step;
156156
o->step = slice.step * self->step;
157+
if (slice.step < 0) {
158+
// Negative slice steps have inclusive stop, so adjust for exclusive
159+
o->stop -= self->step;
160+
}
157161
return MP_OBJ_FROM_PTR(o);
158162
}
159163
#endif

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy