@@ -4,13 +4,14 @@ use crate::common::cell::{
44} ;
55use crate :: function:: OptionalArg ;
66use crate :: obj:: objbytes:: PyBytesRef ;
7+ use crate :: obj:: objsequence:: PySliceableSequence ;
78use crate :: obj:: objslice:: PySliceRef ;
89use crate :: obj:: objstr:: PyStringRef ;
910use crate :: obj:: objtype:: PyClassRef ;
1011use crate :: obj:: { objbool, objiter} ;
1112use crate :: pyobject:: {
1213 BorrowValue , Either , IntoPyObject , PyArithmaticValue , PyClassImpl , PyComparisonValue ,
13- PyIterable , PyObjectRef , PyRef , PyResult , PyValue , TryFromObject ,
14+ PyIterable , PyObject , PyObjectRef , PyRef , PyResult , PyValue , TryFromObject ,
1415} ;
1516use crate :: VirtualMachine ;
1617use crossbeam_utils:: atomic:: AtomicCell ;
@@ -194,14 +195,31 @@ macro_rules! def_array_enum {
194195 }
195196 }
196197
198+ fn getitem_by_slice( & self , slice: PySliceRef , vm: & VirtualMachine ) -> PyResult <PyObjectRef > {
199+ match self {
200+ $( ArrayContentType :: $n( v) => {
201+ let elements = v. get_slice_items( vm, & slice) ?;
202+ let sliced = ArrayContentType :: $n( elements) ;
203+ let obj = PyObject :: new(
204+ PyArray {
205+ array: PyRwLock :: new( sliced)
206+ } ,
207+ PyArray :: class( vm) ,
208+ None
209+ ) ;
210+ Ok ( obj)
211+ } ) *
212+ }
213+ }
214+
197215 fn getitem( & self , needle: Either <isize , PySliceRef >, vm: & VirtualMachine ) -> PyResult {
198216 match needle {
199217 Either :: A ( i) => {
200218 self . idx( i, "array" , vm) . map( |i| {
201219 self . getitem_by_idx( i, vm) . unwrap( )
202220 } )
203221 }
204- Either :: B ( _slice ) => Err ( vm . new_not_implemented_error ( "array slice is not implemented" . to_owned ( ) ) ) ,
222+ Either :: B ( slice ) => self . getitem_by_slice ( slice, vm ) ,
205223 }
206224 }
207225
0 commit comments