Skip to content

Commit 0527c4e

Browse files
committed
Implement array.array.__contains__
1 parent 62aa942 commit 0527c4e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

stdlib/src/array.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,23 @@ mod array {
11601160
zelf.as_object().dict(),
11611161
))
11621162
}
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+
}
11631180
}
11641181

11651182
impl Comparable for PyArray {

0 commit comments

Comments
 (0)