File tree Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -38,8 +38,6 @@ def test_bad_constructor(self):
38
38
self .assertRaises (TypeError , array .array , 'xx' )
39
39
self .assertRaises (ValueError , array .array , 'x' )
40
40
41
- # TODO: RUSTPYTHON
42
- @unittest .expectedFailure
43
41
def test_empty (self ):
44
42
# Exercise code for handling zero-length arrays
45
43
a = array .array ('B' )
@@ -583,8 +581,6 @@ def test_iadd(self):
583
581
584
582
self .assertRaises (TypeError , a .__iadd__ , "bad" )
585
583
586
- # TODO: RUSTPYTHON
587
- @unittest .expectedFailure
588
584
def test_mul (self ):
589
585
a = 5 * array .array (self .typecode , self .example )
590
586
self .assertEqual (
Original file line number Diff line number Diff line change @@ -365,6 +365,23 @@ macro_rules! def_array_enum {
365
365
}
366
366
}
367
367
368
+ fn mul( & self , counter: isize , vm: & VirtualMachine ) -> PyObjectRef {
369
+ let counter = if counter < 0 { 0 } else { counter as usize } ;
370
+ match self {
371
+ $( ArrayContentType :: $n( v) => {
372
+ let elements = v. iter( ) . cycle( ) . take( v. len( ) * counter) . cloned( ) . collect( ) ;
373
+ let sliced = ArrayContentType :: $n( elements) ;
374
+ PyObject :: new(
375
+ PyArray {
376
+ array: PyRwLock :: new( sliced)
377
+ } ,
378
+ PyArray :: class( vm) ,
379
+ None
380
+ )
381
+ } ) *
382
+ }
383
+ }
384
+
368
385
fn repr( & self , _vm: & VirtualMachine ) -> PyResult <String > {
369
386
// we don't need ReprGuard here
370
387
let s = match self {
@@ -636,6 +653,16 @@ impl PyArray {
636
653
}
637
654
}
638
655
656
+ #[ pymethod( name = "__mul__" ) ]
657
+ fn mul ( & self , counter : isize , vm : & VirtualMachine ) -> PyObjectRef {
658
+ self . borrow_value ( ) . mul ( counter, vm)
659
+ }
660
+
661
+ #[ pymethod( name = "__rmul__" ) ]
662
+ fn rmul ( & self , counter : isize , vm : & VirtualMachine ) -> PyObjectRef {
663
+ self . mul ( counter, & vm)
664
+ }
665
+
639
666
#[ pymethod( name = "__repr__" ) ]
640
667
fn repr ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyResult < String > {
641
668
zelf. borrow_value ( ) . repr ( vm)
You can’t perform that action at this time.
0 commit comments