Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/test/test_itertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ def test_chain_reducible(self):
self.assertRaises(TypeError, list, oper(chain(2, 3)))
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
self.pickletest(proto, chain('abc', 'def'), compare=list('abcdef'))
# TODO: RUSTPYTHON
@unittest.expectedFailure

def test_chain_setstate(self):
self.assertRaises(TypeError, chain().__setstate__, ())
self.assertRaises(TypeError, chain().__setstate__, [])
Expand All @@ -209,6 +208,7 @@ def test_chain_setstate(self):
it = chain()
it.__setstate__((iter(['abc', 'def']), iter(['ghi'])))
self.assertEqual(list(it), ['ghi', 'a', 'b', 'c', 'd', 'e', 'f'])

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_combinations(self):
Expand Down
29 changes: 29 additions & 0 deletions vm/src/stdlib/itertools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,36 @@ mod decl {
fn class_getitem(cls: PyTypeRef, args: PyObjectRef, vm: &VirtualMachine) -> PyGenericAlias {
PyGenericAlias::new(cls, args, vm)
}

#[pymethod(magic)]
fn setstate(&self, state: PyTupleRef, vm: &VirtualMachine) -> PyResult<()> {
let args = state.as_slice();
if args.is_empty() {
let msg = String::from("function takes at leat 1 arguments (0 given)");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leat should be least.

return Err(vm.new_type_error(msg));
}
if args.len() > 2 {
let msg = format!("function takes at most 2 arguments ({} given)", args.len());
return Err(vm.new_type_error(msg));
}
let source = &args[0];
let active = args.get(1);
if !PyIter::check(source.as_ref())
|| !active.map_or(true, |active| PyIter::check(active.as_ref()))
{
return Err(vm.new_type_error(String::from("Arguments must be iterators.")));
}
*self.iterables.write() = source.try_to_value(vm)?;
self.cur_idx.store(0);
*self.cached_iter.write() = if let Some(active) = active {
Some(active.clone().get_iter(vm)?)
} else {
None
};
Ok(())
}
}

impl IterNextIterable for PyItertoolsChain {}
impl IterNext for PyItertoolsChain {
fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
Expand Down