8000 Merge remote-tracking branch 'upstream/main' into cleanup-itertools · RustPython/RustPython@10a8566 · GitHub
[go: up one dir, main page]

Skip to content

Commit 10a8566

Browse files
committed
Merge remote-tracking branch 'upstream/main' into cleanup-itertools
2 parents 1f93b95 + 18fdf85 commit 10a8566

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

Lib/test/test_itertools.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,8 +1182,6 @@ def test_pairwise(self):
11821182
with self.assertRaises(TypeError):
11831183
pairwise(None) # non-iterable argument
11841184

1185-
# TODO: RUSTPYTHON
1186-
@unittest.skip("TODO: RUSTPYTHON, hangs")
11871185
def test_pairwise_reenter(self):
11881186
def check(reenter_at, expected):
11891187
class I:
@@ -1234,8 +1232,6 @@ def __next__(self):
12341232
([5], [6]),
12351233
])
12361234

1237-
# TODO: RUSTPYTHON
1238-
@unittest.skip("TODO: RUSTPYTHON, hangs")
12391235
def test_pairwise_reenter2(self):
12401236
def check(maxcount, expected):
12411237
class I:

vm/src/stdlib/itertools.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,12 +1922,25 @@ mod decl {
19221922

19231923
impl IterNext for PyItertoolsPairwise {
19241924
fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
1925-
let old = match zelf.old.read().clone() {
1926-
None => handle_pyiter_return!(zelf.iterator.next(vm)?),
1925+
let old_clone = {
1926+
let guard = zelf.old.read();
1927+
guard.clone()
1928+
};
A0F0 1929+
let old = match old_clone {
1930+
None => match zelf.iterator.next(vm)? {
1931+
PyIterReturn::Return(obj) => {
1932+
// Needed for when we reenter
1933+
*zelf.old.write() = Some(obj.clone());
1934+
obj
1935+
}
1936+
PyIterReturn::StopIteration(v) => return Ok(PyIterReturn::StopIteration(v)),
1937+
},
19271938
Some(obj) => obj,
19281939
};
1940+
19291941
let new = handle_pyiter_return!(zelf.iterator.next(vm)?);
19301942
*zelf.old.write() = Some(new.clone());
1943+
19311944
Ok(PyIterReturn::Return(vm.new_tuple((old, new)).into()))
19321945
}
19331946
}

0 commit comments

Comments
 (0)
0