diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py index 7cca83d78..d1b2f03f4 100644 --- a/Lib/test/test_array.py +++ b/Lib/test/test_array.py @@ -918,8 +918,6 @@ class BaseTest: del a[start:stop:step] self.assertEqual(a, array.array(self.typecode, L)) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_index(self): example = 2*self.example a = array.array(self.typecode, example) @@ -929,8 +927,6 @@ class BaseTest: self.assertRaises(ValueError, a.index, None) self.assertRaises(ValueError, a.index, self.outside) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_count(self): example = 2*self.example a = array.array(self.typecode, example) @@ -940,8 +936,6 @@ class BaseTest: self.assertEqual(a.count(self.outside), 0) self.assertEqual(a.count(None), 0) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_remove(self): for x in self.example: example = 2*self.example diff --git a/vm/src/stdlib/array.rs b/vm/src/stdlib/array.rs index 87c2afaa2..4e397d1f4 100644 --- a/vm/src/stdlib/array.rs +++ b/vm/src/stdlib/array.rs @@ -99,8 +99,9 @@ macro_rules! def_array_enum { fn count(&self, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult { match self { $(ArrayContentType::$n(v) => { - let val = $t::try_from_object(vm, obj)?; - Ok(v.iter().filter(|&&a| a == val).count()) + Ok(>::try_from_object(vm, obj)?.map_or(0, |val| { + v.iter().filter(|&&a| a == val).count() + })) })* } } @@ -108,11 +109,15 @@ macro_rules! def_array_enum { fn remove(&mut self, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<()>{ match self { $(ArrayContentType::$n(v) => { - let val = $t::try_from_object(vm, obj)?; - if let Some(pos) = v.iter().position(|&a| a == val) { - v.remove(pos); - } else { - return Err(vm.new_value_error("array.remove(x): x not in array".to_owned())); + let pos = >::try_from_object(vm, obj)?.map_or(None, |val| { + v.iter().position(|&a| a == val) + }); + + match pos { + Some(x) => { + v.remove(x); + }, + None => return Err(vm.new_value_error("array.remove(x): x not in array".to_owned())) } })* } @@ -147,8 +152,9 @@ macro_rules! def_array_enum { fn index(&self, x: PyObjectRef, vm: &VirtualMachine) -> PyResult> { match self { $(ArrayContentType::$n(v) => { - let val = $t::try_from_object(vm, x)?; - Ok(v.iter().position(|&a| a == val)) + Ok(>::try_from_object(vm, x)?.map_or(None, |val| { + v.iter().position(|&a| a == val) + })) })* } }