File tree 2 files changed +22
-0
lines changed 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -112,3 +112,8 @@ def test_array_frombytes():
112
112
# test arrayiterator name
113
113
i = iter (a )
114
114
assert str (i .__class__ .__name__ ) == "arrayiterator"
115
+
116
+ # teset array.__contains__
117
+ a = array ('B' , [0 ])
118
+ assert a .__contains__ (0 )
119
+ assert not a .__contains__ (1 )
Original file line number Diff line number Diff line change @@ -1160,6 +1160,23 @@ mod array {
1160
1160
zelf. as_object ( ) . dict ( ) ,
1161
1161
) )
1162
1162
}
1163
+
1164
+ #[ pymethod( magic) ]
1165
+ fn contains ( & self , value : PyObjectRef , vm : & VirtualMachine ) -> bool {
1166
+ let array = self . array . read ( ) ;
1167
+ for element in array
1168
+ . iter ( vm)
1169
+ . map ( |x| x. expect ( "Expected to be checked by array.len() and read lock." ) )
1170
+ {
1171
+ if let Ok ( true ) =
1172
+ element. rich_compare_bool ( value. as_object ( ) , PyComparisonOp :: Eq , vm)
1173
+ {
1174
+ return true ;
1175
+ }
1176
+ }
1177
+
1178
+ false
1179
+ }
1163
1180
}
1164
1181
1165
1182
impl Comparable for PyArray {
You can’t perform that action at this time.
0 commit comments