Merge pull request #3988 from jeffwang0516/starmap-reduce

Add `itertools.starmap.__reduce__`
This commit is contained in:
Jeong YunWon
2022-08-01 19:36:49 +09:00
committed by GitHub
2 changed files with 9 additions and 3 deletions

View File

@@ -1226,8 +1226,6 @@ class TestBasicOps(unittest.TestCase):
c = map(tupleize, 'abc', count())
self.pickletest(proto, c)
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_starmap(self):
self.assertEqual(list(starmap(operator.pow, zip(range(3), range(1,7)))),
[0**1, 1**2, 2**3])

View File

@@ -404,7 +404,15 @@ mod decl {
}
#[pyimpl(with(IterNext, Constructor), flags(BASETYPE))]
impl PyItertoolsStarmap {}
impl PyItertoolsStarmap {
#[pymethod(magic)]
fn reduce(zelf: PyRef<Self>) -> (PyTypeRef, (PyObjectRef, PyIter)) {
(
zelf.class().clone(),
(zelf.function.clone(), zelf.iterable.clone()),
)
}
}
impl IterNextIterable for PyItertoolsStarmap {}
impl IterNext for PyItertoolsStarmap {
fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {