diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index 6fe1524d68..ef5602d083 100644 --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -818,8 +818,6 @@ def _check_iterator(it): with self.assertRaises(struct.error): s.iter_unpack(b"12") - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_uninstantiable(self): iter_unpack_type = type(struct.Struct(">ibcp").iter_unpack(b"")) self.assertRaises(TypeError, iter_unpack_type) diff --git a/stdlib/src/pystruct.rs b/stdlib/src/pystruct.rs index 31f22c05f4..e5f71cad13 100644 --- a/stdlib/src/pystruct.rs +++ b/stdlib/src/pystruct.rs @@ -16,7 +16,7 @@ pub(crate) mod _struct { function::{ArgBytesLike, ArgMemoryBuffer, PosArgs}, match_class, protocol::PyIterReturn, - types::{Constructor, IterNext, Iterable, Representable, SelfIter}, + types::{Constructor, IterNext, Iterable, Representable, SelfIter, Unconstructible}, }; use crossbeam_utils::atomic::AtomicCell; @@ -163,7 +163,7 @@ pub(crate) mod _struct { } impl UnpackIterator { - fn new( + fn with_buffer( vm: &VirtualMachine, format_spec: FormatSpec, buffer: ArgBytesLike, @@ -191,7 +191,7 @@ pub(crate) mod _struct { } } - #[pyclass(with(IterNext, Iterable))] + #[pyclass(with(Unconstructible, IterNext, Iterable))] impl UnpackIterator { #[pymethod(magic)] fn length_hint(&self) -> usize { @@ -199,6 +199,7 @@ pub(crate) mod _struct { } } impl SelfIter for UnpackIterator {} + impl Unconstructible for UnpackIterator {} impl IterNext for UnpackIterator { fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { let size = zelf.format_spec.size; @@ -222,7 +223,7 @@ pub(crate) mod _struct { vm: &VirtualMachine, ) -> PyResult { let format_spec = fmt.format_spec(vm)?; - UnpackIterator::new(vm, format_spec, buffer) + UnpackIterator::with_buffer(vm, format_spec, buffer) } #[pyfunction] @@ -302,7 +303,7 @@ pub(crate) mod _struct { buffer: ArgBytesLike, vm: &VirtualMachine, ) -> PyResult { - UnpackIterator::new(vm, self.spec.clone(), buffer) + UnpackIterator::with_buffer(vm, self.spec.clone(), buffer) } }