Skip to content

Commit ad3b836

Browse files
committed
Fix UnpackIterator constructor
1 parent 44d3124 commit ad3b836

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

Lib/test/test_struct.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,6 @@ def _check_iterator(it):
818818
with self.assertRaises(struct.error):
819819
s.iter_unpack(b"12")
820820

821-
# TODO: RUSTPYTHON
822-
@unittest.expectedFailure
823821
def test_uninstantiable(self):
824822
iter_unpack_type = type(struct.Struct(">ibcp").iter_unpack(b""))
825823
self.assertRaises(TypeError, iter_unpack_type)

stdlib/src/pystruct.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub(crate) mod _struct {
1616
function::{ArgBytesLike, ArgMemoryBuffer, PosArgs},
1717
match_class,
1818
protocol::PyIterReturn,
19-
types::{Constructor, IterNext, Iterable, Representable, SelfIter},
19+
types::{Constructor, IterNext, Iterable, Representable, SelfIter, Unconstructible},
2020
};
2121
use crossbeam_utils::atomic::AtomicCell;
2222

@@ -163,7 +163,7 @@ pub(crate) mod _struct {
163163
}
164164

165165
impl UnpackIterator {
166-
fn new(
166+
fn with_buffer(
167167
vm: &VirtualMachine,
168168
format_spec: FormatSpec,
169169
buffer: ArgBytesLike,
@@ -191,14 +191,15 @@ pub(crate) mod _struct {
191191
}
192192
}
193193

194-
#[pyclass(with(IterNext, Iterable))]
194+
#[pyclass(with(Unconstructible, IterNext, Iterable))]
195195
impl UnpackIterator {
196196
#[pymethod(magic)]
197197
fn length_hint(&self) -> usize {
198198
self.buffer.len().saturating_sub(self.offset.load()) / self.format_spec.size
199199
}
200200
}
201201
impl SelfIter for UnpackIterator {}
202+
impl Unconstructible for UnpackIterator {}
202203
impl IterNext for UnpackIterator {
203204
fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
204205
let size = zelf.format_spec.size;
@@ -222,7 +223,7 @@ pub(crate) mod _struct {
222223
vm: &VirtualMachine,
223224
) -> PyResult<UnpackIterator> {
224225
let format_spec = fmt.format_spec(vm)?;
225-
UnpackIterator::new(vm, format_spec, buffer)
226+
UnpackIterator::with_buffer(vm, format_spec, buffer)
226227
}
227228

228229
#[pyfunction]
@@ -302,7 +303,7 @@ pub(crate) mod _struct {
302303
buffer: ArgBytesLike,
303304
vm: &VirtualMachine,
304305
) -> PyResult<UnpackIterator> {
305-
UnpackIterator::new(vm, self.spec.clone(), buffer)
306+
UnpackIterator::with_buffer(vm, self.spec.clone(), buffer)
306307
}
307308
}
308309

0 commit comments

Comments
 (0)