You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sort() of a range() that does not land exactly on stop returns wrong values #3228
sort() applied to a range() sweep returns the wrong elements whenever the range does not land exactly on stop (i.e. when the last element != stop - step).
_sort_sweep rebuilds the reversed range by deriving the new endpoints from sweep.stop, but stop is exclusive and frequently does not coincide with the last element, so the rebuilt range has wrong values (and sometimes a wrong element count).
sort() should return the original range's elements in sorted order, e.g. sort(range(0, 5, 2), reverse=True) should yield [4, 2, 0].
Notes
The existing tests only cover ranges that land exactly on stop (range(1, 10), range(1, 10, 3), range(0, 2, 0.5)), where the old formula coincidentally produces the correct answer — which is why this went unnoticed.
Activity