Skip to content

Commit d236067

Browse files
authored
Merge pull request RustPython#3988 from jeffwang0516/starmap-reduce
Add `itertools.starmap.__reduce__`
2 parents ac48968 + e5437e4 commit d236067

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Lib/test/test_itertools.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,8 +1226,6 @@ def test_map(self):
12261226
c = map(tupleize, 'abc', count())
12271227
self.pickletest(proto, c)
12281228

1229-
# TODO: RUSTPYTHON
1230-
@unittest.expectedFailure
12311229
def test_starmap(self):
12321230
self.assertEqual(list(starmap(operator.pow, zip(range(3), range(1,7)))),
12331231
[0**1, 1**2, 2**3])

vm/src/stdlib/itertools.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,15 @@ mod decl {
404404
}
405405

406406
#[pyimpl(with(IterNext, Constructor), flags(BASETYPE))]
407-
impl PyItertoolsStarmap {}
407+
impl PyItertoolsStarmap {
408+
#[pymethod(magic)]
409+
fn reduce(zelf: PyRef<Self>) -> (PyTypeRef, (PyObjectRef, PyIter)) {
410+
(
411+
zelf.class().clone(),
412+
(zelf.function.clone(), zelf.iterable.clone()),
413+
)
414+
}
415+
}
408416
impl IterNextIterable for PyItertoolsStarmap {}
409417
impl IterNext for PyItertoolsStarmap {
410418
fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {

0 commit comments

Comments
 (0)