Merge pull request #3968 from TwoPair/list-remove

This commit is contained in:
Jeong YunWon
2022-08-07 15:57:29 +09:00
committed by GitHub
5 changed files with 5 additions and 137 deletions

View File

@@ -304,8 +304,6 @@ class CommonTest(seq_tests.CommonTest):
self.assertRaises(TypeError, a.pop, 42, 42)
a = self.type2test([0, 10, 20, 30, 40])
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_remove(self):
a = self.type2test([0, 0, 1])
a.remove(1)
@@ -365,8 +363,6 @@ class CommonTest(seq_tests.CommonTest):
# verify that original order and values are retained.
self.assertIs(x, y)
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_index(self):
super().test_index()
a = self.type2test([-2, -1, 0, 0, 1, 2])

View File

@@ -929,21 +929,6 @@ class TestSequence(seq_tests.CommonTest):
# For now, bypass tests that require slicing
self.skipTest("Exhausted deque iterator doesn't free a deque")
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_contains_fake(self): # XXX: RUSTPYTHON; the method also need to be removed when done
super().test_contains_fake()
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_count(self): # XXX: RUSTPYTHON; the method also need to be removed when done
super().test_count()
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_index(self): # XXX: RUSTPYTHON; the method also need to be removed when done
super().test_index()
#==============================================================================
libreftest = """

10
Lib/test/test_list.py vendored
View File

@@ -231,15 +231,5 @@ class ListTest(list_tests.CommonTest):
lst = [X(), X()]
X() in lst
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_count(self): # XXX: RUSTPYTHON; the method also need to be removed when done
super().test_count()
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_contains_fake(self): # XXX: RUSTPYTHON; the method also need to be removed when done
super().test_contains_fake()
if __name__ == "__main__":
unittest.main()

View File

@@ -7,16 +7,6 @@ import unittest
class UserListTest(list_tests.CommonTest):
type2test = UserList
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_contains_fake(self): # XXX: RUSTPYTHON; the method also need to be removed when done
super().test_contains_fake()
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_count(self): # XXX: RUSTPYTHON; the method also need to be removed when done
super().test_count()
import sys
@unittest.skipIf(sys.platform == "win32", "TODO: RUSTPYTHON, unexpectedly panics somewhere")
def test_repr_deep(self): # XXX: RUSTPYTHON; remove this method when fixed

View File

@@ -1,10 +1,6 @@
use crate::{
builtins::PyIntRef,
function::{Either, OptionalArg, PyComparisonValue},
sliceable::SequenceIndexOp,
types::{richcompare_wrapper, PyComparisonOp, RichCompareFunc},
vm::VirtualMachine,
AsObject, PyObject, PyObjectRef, PyResult,
builtins::PyIntRef, function::OptionalArg, sliceable::SequenceIndexOp, types::PyComparisonOp,
vm::VirtualMachine, AsObject, PyObject, PyObjectRef, PyResult,
};
use optional::Optioned;
use std::ops::Range;
@@ -50,11 +46,6 @@ pub trait MutObjectSequenceOp<'a> {
where
F: FnMut(),
{
let needle_cls = needle.class();
let needle_cmp = needle_cls
.mro_find_map(|cls| cls.slots.richcompare.load())
.unwrap();
let mut borrower = None;
let mut i = range.start;
@@ -81,94 +72,10 @@ pub trait MutObjectSequenceOp<'a> {
}
borrower = Some(guard);
} else {
let elem_cls = elem.class();
let reverse_first =
!elem_cls.is(&needle_cls) && elem_cls.fast_issubclass(&needle_cls);
let elem = elem.clone();
drop(guard);
let eq = if reverse_first {
let elem_cmp = elem_cls
.mro_find_map(|cls| cls.slots.richcompare.load())
.unwrap();
drop(elem_cls);
fn cmp(
elem: &PyObject,
needle: &PyObject,
elem_cmp: RichCompareFunc,
needle_cmp: RichCompareFunc,
vm: &VirtualMachine,
) -> PyResult<bool> {
match elem_cmp(elem, needle, PyComparisonOp::Eq, vm)? {
Either::B(PyComparisonValue::Implemented(value)) => Ok(value),
Either::A(obj) if !obj.is(&vm.ctx.not_implemented) => {
obj.try_to_bool(vm)
}
_ => match needle_cmp(needle, elem, PyComparisonOp::Eq, vm)? {
Either::B(PyComparisonValue::Implemented(value)) => Ok(value),
Either::A(obj) if !obj.is(&vm.ctx.not_implemented) => {
obj.try_to_bool(vm)
}
_ => Ok(false),
},
}
}
if elem_cmp as usize == richcompare_wrapper as usize {
let elem = elem.clone();
drop(guard);
cmp(&elem, needle, elem_cmp, needle_cmp, vm)?
} else {
let eq = cmp(elem, needle, elem_cmp, needle_cmp, vm)?;
borrower = Some(guard);
eq
}
} else {
match needle_cmp(needle, elem, PyComparisonOp::Eq, vm)? {
Either::B(PyComparisonValue::Implemented(value)) => {
drop(elem_cls);
borrower = Some(guard);
value
}
Either::A(obj) if !obj.is(&vm.ctx.not_implemented) => {
drop(elem_cls);
borrower = Some(guard);
obj.try_to_bool(vm)?
}
_ => {
let elem_cmp = elem_cls
.mro_find_map(|cls| cls.slots.richcompare.load())
.unwrap();
drop(elem_cls);
fn cmp(
elem: &PyObject,
needle: &PyObject,
elem_cmp: RichCompareFunc,
vm: &VirtualMachine,
) -> PyResult<bool> {
match elem_cmp(elem, needle, PyComparisonOp::Eq, vm)? {
Either::B(PyComparisonValue::Implemented(value)) => Ok(value),
Either::A(obj) if !obj.is(&vm.ctx.not_implemented) => {
obj.try_to_bool(vm)
}
_ => Ok(false),
}
}
if elem_cmp as usize == richcompare_wrapper as usize {
let elem = elem.clone();
drop(guard);
cmp(&elem, needle, elem_cmp, vm)?
} else {
let eq = cmp(elem, needle, elem_cmp, vm)?;
borrower = Some(guard);
eq
}
}
}
};
if eq {
if elem.rich_compare_bool(needle, PyComparisonOp::Eq, vm)? {
f();
if SHORT {
break Optioned::<usize>::some(i);