From 7be043fa5a73c19a32161ae7ae05ad90570f0f57 Mon Sep 17 00:00:00 2001 From: jfh Date: Mon, 14 Jun 2021 22:30:06 +0300 Subject: [PATCH] Fix small miscalculation when reversing a range. --- Lib/test/test_range.py | 2 -- vm/src/builtins/range.rs | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Lib/test/test_range.py b/Lib/test/test_range.py index 96b54be87..efe7cdc3a 100644 --- a/Lib/test/test_range.py +++ b/Lib/test/test_range.py @@ -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), diff --git a/vm/src/builtins/range.rs b/vm/src/builtins/range.rs index 0ce10f014..e99fc93a9 100644 --- a/vm/src/builtins/range.rs +++ b/vm/src/builtins/range.rs @@ -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),