diff --git a/vm/src/stdlib/itertools.rs b/vm/src/stdlib/itertools.rs index dcc6dcd3b..f114d8076 100644 --- a/vm/src/stdlib/itertools.rs +++ b/vm/src/stdlib/itertools.rs @@ -958,7 +958,7 @@ impl PyItertoolsCombinations { struct PyItertoolsZiplongest { iterators: Vec, fillvalue: PyObjectRef, - numactive: RefCell, + numactive: Cell, } impl PyValue for PyItertoolsZiplongest { @@ -992,7 +992,7 @@ impl PyItertoolsZiplongest { .map(|iterable| get_iter(vm, &iterable)) .collect::, _>>()?; - let numactive = RefCell::new(iterators.len()); + let numactive = Cell::new(iterators.len()); PyItertoolsZiplongest { iterators, @@ -1007,14 +1007,16 @@ impl PyItertoolsZiplongest { if self.iterators.is_empty() { Err(new_stop_iteration(vm)) } else { - let mut next_obj: PyObjectRef; let mut result: Vec = Vec::new(); - let mut numactive = self.numactive.clone().into_inner(); + let mut numactive = self.numactive.get(); for idx in 0..self.iterators.len() { - next_obj = match call_next(vm, &self.iterators[idx]) { + let next_obj = match call_next(vm, &self.iterators[idx]) { Ok(obj) => obj, - Err(_) => { + Err(err) => { + if !objtype::isinstance(&err, &vm.ctx.exceptions.stop_iteration) { + return Err(err); + } numactive -= 1; if numactive == 0 { return Err(new_stop_iteration(vm));