Skip to content

Commit 2b09682

Browse files
author
Brad Walker
committed
simplified newrange.__reversed__ and corrected return type
1 parent e84bab2 commit 2b09682

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

src/future/types/newrange.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,7 @@ def __contains__(self, value):
107107
return False
108108

109109
def __reversed__(self):
110-
"""Return a range which represents a sequence whose
111-
contents are the same as the sequence this range
112-
represents, but in the opposite order."""
113-
sign = self._step / abs(self._step)
114-
last = self._start + ((self._len - 1) * self._step)
115-
return newrange(last, self._start - sign, -1 * self._step)
110+
return iter(self[::-1])
116111

117112
def __getitem__(self, index):
118113
"""Return the element at position ``index`` in the sequence

tests/test_future/test_range.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
from future.builtins import range
77
from future.tests.base import unittest
88

9-
from collections import Sequence
9+
from collections import Iterator, Sequence
1010

1111

1212
class RangeTests(unittest.TestCase):
1313
def test_range(self):
1414
self.assertTrue(isinstance(range(0), Sequence))
15+
self.assertTrue(isinstance(reversed(range(0)), Iterator))
1516

1617
def test_bool_range(self):
1718
self.assertFalse(range(0))

0 commit comments

Comments
 (0)