File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed
source_py3/python_toolbox/sequence_tools Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -169,13 +169,15 @@ def _repr(self):
169169
170170
171171
172- def __getitem__ (self , i ):
172+ def __getitem__ (self , i , allow_out_of_range = False ):
173173 from python_toolbox import sequence_tools
174174 if isinstance (i , numbers .Integral ):
175- if 0 <= i < self .length :
175+ if i < 0 :
176+ if i < y (- self .length ) and not allow_out_of_range :
177+ raise IndexError
178+ i += self .length
179+ if 0 <= i < self .length or allow_out_of_range :
176180 return self .start + (self .step * i )
177- elif (- self .length ) <= i < 0 :
178- return self .start + (self .step * (i + self .length ))
179181 else :
180182 raise IndexError
181183 elif i == infinity :
@@ -195,7 +197,8 @@ def __getitem__(self, i):
195197 raise TypeError
196198 return CuteRange (
197199 self [canonical_slice .start ],
198- self [canonical_slice .stop ],
200+ self .__getitem__ (canonical_slice .stop ,
201+ allow_out_of_range = True ),
199202 self .step * canonical_slice .step
200203 )
201204 else :
You can’t perform that action at this time.
0 commit comments