@@ -354,6 +354,17 @@ macro_rules! def_array_enum {
354
354
}
355
355
}
356
356
357
+ fn iadd( & mut self , other: ArrayContentType , vm: & VirtualMachine ) -> PyResult <( ) > {
358
+ match self {
359
+ $( ArrayContentType :: $n( v) => if let ArrayContentType :: $n( mut other) = other {
360
+ v. append( & mut other) ;
361
+ Ok ( ( ) )
362
+ } else {
363
+ Err ( vm. new_type_error( "can only extend with array of same kind" . to_owned( ) ) )
364
+ } , ) *
365
+ }
366
+ }
367
+
357
368
fn repr( & self , _vm: & VirtualMachine ) -> PyResult <String > {
358
369
// we don't need ReprGuard here
359
370
let s = match self {
@@ -604,7 +615,24 @@ impl PyArray {
604
615
if let Some ( other) = other. payload :: < PyArray > ( ) {
605
616
self . borrow_value ( ) . add ( & * other. borrow_value ( ) , vm)
606
617
} else {
607
- Err ( vm. new_type_error ( format ! ( "can only append array (not \" {}\" ) to array" , other. class( ) . name) ) )
618
+ Err ( vm. new_type_error ( format ! (
619
+ "can only append array (not \" {}\" ) to array" ,
620
+ other. class( ) . name
621
+ ) ) )
622
+ }
623
+ }
624
+
625
+ #[ pymethod( name = "__iadd__" ) ]
626
+ fn iadd ( zelf : PyRef < Self > , other : PyObjectRef , vm : & VirtualMachine ) -> PyResult < PyObjectRef > {
627
+ if let Some ( other) = other. payload :: < PyArray > ( ) {
628
+ let other = other. borrow_value ( ) . clone ( ) ;
629
+ let result = zelf. borrow_value_mut ( ) . iadd ( other, vm) ;
630
+ result. map ( |_| zelf. into_object ( ) )
631
+ } else {
632
+ Err ( vm. new_type_error ( format ! (
633
+ "can only extend array with array (not \" {}\" )" ,
634
+ other. class( ) . name
635
+ ) ) )
608
636
}
609
637
}
610
638
0 commit comments