1- use super :: { PositionIterInternal , PyGenericAlias , PyTupleRef , PyType , PyTypeRef } ;
1+ use super :: { PositionIterInternal , PyGenericAlias , PyIntRef , PyTupleRef , PyType , PyTypeRef } ;
22use crate :: common:: lock:: {
33 PyMappedRwLockReadGuard , PyMutex , PyRwLock , PyRwLockReadGuard , PyRwLockWriteGuard ,
44} ;
@@ -10,7 +10,7 @@ use crate::{
1010 protocol:: { PyIterReturn , PyMappingMethods , PySequence , PySequenceMethods } ,
1111 recursion:: ReprGuard ,
1212 sequence:: { MutObjectSequenceOp , SequenceExt , SequenceMutExt } ,
13- sliceable:: { saturate_index , SequenceIndex , SliceableSequenceMutOp , SliceableSequenceOp } ,
13+ sliceable:: { pyint_saturate_index , SequenceIndex , SliceableSequenceMutOp , SliceableSequenceOp } ,
1414 types:: {
1515 AsMapping , AsSequence , Comparable , Constructor , Hashable , Initializer , IterNext ,
1616 IterNextIterable , Iterable , PyComparisonOp , Unconstructible , Unhashable ,
@@ -271,15 +271,17 @@ impl PyList {
271271 fn index (
272272 & self ,
273273 needle : PyObjectRef ,
274- start : OptionalArg < isize > ,
275- stop : OptionalArg < isize > ,
274+ start : OptionalArg < PyObjectRef > ,
275+ stop : OptionalArg < PyObjectRef > ,
276276 vm : & VirtualMachine ,
277277 ) -> PyResult < usize > {
278278 let len = self . len ( ) ;
279- let start = start. map ( |i| saturate_index ( i, len) ) . unwrap_or ( 0 ) ;
280- let stop = stop
281- . map ( |i| saturate_index ( i, len) )
282- . unwrap_or ( isize:: MAX as usize ) ;
279+ let saturate = |obj : PyObjectRef , len| -> PyResult < _ > {
280+ obj. try_into_value ( vm)
281+ . map ( |int : PyIntRef | pyint_saturate_index ( int, len) )
282+ } ;
283+ let start = start. map_or ( Ok ( 0 ) , |obj| saturate ( obj, len) ) ?;
284+ let stop = stop. map_or ( Ok ( len) , |obj| saturate ( obj, len) ) ?;
283285 let index = self . mut_index_range ( vm, & needle, start..stop) ?;
284286 if let Some ( index) = index. into ( ) {
285287 Ok ( index)
0 commit comments