Skip to content

Commit fbd727e

Browse files
committed
Fix numactive to immutable and Cell type, clarify error handling
1 parent af95003 commit fbd727e

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

vm/src/stdlib/itertools.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ impl PyItertoolsCombinations {
958958
struct PyItertoolsZiplongest {
959959
iterators: Vec<PyObjectRef>,
960960
fillvalue: PyObjectRef,
961-
numactive: RefCell<usize>,
961+
numactive: Cell<usize>,
962962
}
963963

964964
impl PyValue for PyItertoolsZiplongest {
@@ -992,7 +992,7 @@ impl PyItertoolsZiplongest {
992992
.map(|iterable| get_iter(vm, &iterable))
993993
.collect::<Result<Vec<_>, _>>()?;
994994

995-
let numactive = RefCell::new(iterators.len());
995+
let numactive = Cell::new(iterators.len());
996996

997997
PyItertoolsZiplongest {
998998
iterators,
@@ -1007,14 +1007,16 @@ impl PyItertoolsZiplongest {
10071007
if self.iterators.is_empty() {
10081008
Err(new_stop_iteration(vm))
10091009
} else {
1010-
let mut next_obj: PyObjectRef;
10111010
let mut result: Vec<PyObjectRef> = Vec::new();
1012-
let mut numactive = self.numactive.clone().into_inner();
1011+
let mut numactive = self.numactive.get();
10131012

10141013
for idx in 0..self.iterators.len() {
1015-
next_obj = match call_next(vm, &self.iterators[idx]) {
1014+
let next_obj = match call_next(vm, &self.iterators[idx]) {
10161015
Ok(obj) => obj,
1017-
Err(_) => {
1016+
Err(err) => {
1017+
if !objtype::isinstance(&err, &vm.ctx.exceptions.stop_iteration) {
1018+
return Err(err);
1019+
}
10181020
numactive -= 1;
10191021
if numactive == 0 {
10201022
return Err(new_stop_iteration(vm));

0 commit comments

Comments
 (0)