Skip to content

Commit ceabcb1

Browse files
committed
-
1 parent afd8575 commit ceabcb1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

source_py3/python_toolbox/sequence_tools/cute_range.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,20 @@ def __getitem__(self, i):
176176
return self.start + (self.step * (i + self.length))
177177
else:
178178
raise IndexError
179+
elif i == infinity:
180+
if self.length == infinity:
181+
return self.stop
182+
else:
183+
raise IndexError
184+
elif i == -infinity:
185+
raise IndexError
179186
elif isinstance(i, (slice, sequence_tools.CanonicalSlice)):
180187
canonical_slice = sequence_tools.CanonicalSlice(
181188
i, iterable_or_length=self
182189
)
183-
if not (0 <= canonical_slice.start < self.length and
184-
0 <= canonical_slice.stop < self.length):
190+
if not ((0 <= canonical_slice.start < self.length) and
191+
((0 <= canonical_slice.stop < self.length) or
192+
(canonical_slice.stop == self.length == infinity))):
185193
raise TypeError
186194
return CuteRange(
187195
self[canonical_slice.start],

0 commit comments

Comments
 (0)