diff --git a/Lib/test/list_tests.py b/Lib/test/list_tests.py index 63f7fe24f..e939c99dd 100644 --- a/Lib/test/list_tests.py +++ b/Lib/test/list_tests.py @@ -12,8 +12,6 @@ from test import support, seq_tests class CommonTest(seq_tests.CommonTest): - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_init(self): # Iterable arg is optional self.assertEqual(self.type2test([]), self.type2test()) diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py index 73a15d1ef..8bf2f8665 100644 --- a/Lib/test/test_set.py +++ b/Lib/test/test_set.py @@ -47,8 +47,6 @@ class TestJointOps: self.s = self.thetype(word) self.d = dict.fromkeys(word) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_new_or_init(self): self.assertRaises(TypeError, self.thetype, [], 2) self.assertRaises(TypeError, set().__init__, a=1) @@ -386,8 +384,6 @@ class TestSet(TestJointOps, unittest.TestCase): def test_contains(self): super().test_contains() - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_init(self): s = self.thetype() s.__init__(self.word) diff --git a/vm/src/builtins/dict.rs b/vm/src/builtins/dict.rs index b278cff59..d5d3988e8 100644 --- a/vm/src/builtins/dict.rs +++ b/vm/src/builtins/dict.rs @@ -54,10 +54,7 @@ impl PyValue for PyDict { impl PyDict { #[pyslot] fn tp_new(class: PyTypeRef, _args: FuncArgs, vm: &VirtualMachine) -> PyResult> { - PyDict { - entries: DictContentType::default(), - } - .into_ref_with_type(vm, class) + PyDict::default().into_ref_with_type(vm, class) } #[pymethod(magic)] diff --git a/vm/src/builtins/list.rs b/vm/src/builtins/list.rs index 3f7a15038..09716a24d 100644 --- a/vm/src/builtins/list.rs +++ b/vm/src/builtins/list.rs @@ -391,16 +391,21 @@ impl PyList { #[pyslot] fn tp_new( cls: PyTypeRef, - iterable: OptionalArg, + _iterable: OptionalArg, vm: &VirtualMachine, ) -> PyResult> { - let elements = if let OptionalArg::Present(iterable) = iterable { + PyList::default().into_ref_with_type(vm, cls) + } + + #[pymethod(name = "__init__")] + fn init(&self, iterable: OptionalArg, vm: &VirtualMachine) -> PyResult<()> { + let mut elements = if let OptionalArg::Present(iterable) = iterable { vm.extract_elements(&iterable)? } else { vec![] }; - - PyList::from(elements).into_ref_with_type(vm, cls) + std::mem::swap(self.borrow_vec_mut().deref_mut(), &mut elements); + Ok(()) } } diff --git a/vm/src/builtins/set.rs b/vm/src/builtins/set.rs index af5c02dcb..fc34d24f3 100644 --- a/vm/src/builtins/set.rs +++ b/vm/src/builtins/set.rs @@ -78,14 +78,6 @@ impl PySetInner { Ok(set) } - fn from_arg(iterable: OptionalArg, vm: &VirtualMachine) -> PyResult { - if let OptionalArg::Present(iterable) = iterable { - Self::new(iterable, vm) - } else { - Ok(PySetInner::default()) - } - } - fn len(&self) -> usize { self.content.len() } @@ -318,13 +310,21 @@ impl PySet { #[pyslot] fn tp_new( cls: PyTypeRef, - iterable: OptionalArg, + _iterable: OptionalArg, vm: &VirtualMachine, ) -> PyResult> { - Self { - inner: PySetInner::from_arg(iterable, vm)?, + PySet::default().into_ref_with_type(vm, cls) + } + + #[pymethod(magic)] + fn init(&self, iterable: OptionalArg, vm: &VirtualMachine) -> PyResult<()> { + if self.len() > 0 { + self.clear(); } - .into_ref_with_type(vm, cls) + if let OptionalArg::Present(it) = iterable { + self.update(Args::new(vec![it]), vm)?; + } + Ok(()) } #[pymethod(name = "__len__")]