Merge pull request #4190 from dvermd/takewhile_reduce

add takewhile.__reduce__
This commit is contained in:
Jeong YunWon
2022-10-02 16:17:37 +09:00
committed by GitHub
2 changed files with 9 additions and 3 deletions

View File

@@ -1349,8 +1349,6 @@ class TestBasicOps(unittest.TestCase):
self.assertEqual(list(islice(range(100), IntLike(10), IntLike(50), IntLike(5))),
list(range(10,50,5)))
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_takewhile(self):
data = [1, 3, 5, 20, 2, 4, 6, 8]
self.assertEqual(list(takewhile(underten, data)), [1, 3, 5])

View File

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