Fix small miscalculation when reversing a range.

This commit is contained in:
jfh committed 2021-06-14 22:31:50 +03:00
1 parent e63d2741c3
commit 7be043fa5a
2 files changed
+1 -5

No files matched your search

-2
View File
@@ -582,8 +582,6 @@ class RangeTest(unittest.TestCase):
self.assertNotIn(10, r)
self.assertNotIn("", r)
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_reverse_iteration(self):
for r in [range(10),
range(0),
+1 -3
View File
@@ -188,19 +188,17 @@ impl PyRange {
// compute the last element that is actually contained within the range
// this is the new start
let remainder = ((stop - start) % step).abs();
let remainder = (stop - start) % step;
let new_start = if remainder.is_zero() {
stop - step
} else {
stop - &remainder
};
let new_stop: BigInt = match step.sign() {
Sign::Plus => start - 1,
Sign::Minus => start + 1,
Sign::NoSign => unreachable!(),
};
let reversed = PyRange {
start: new_start.into_pyref(vm),
stop: new_stop.into_pyref(vm),