Skip to content

Commit 164e343

Browse files
committed
add takewhile.__reduce__
1 parent 3301220 commit 164e343

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
@@ -1349,8 +1349,6 @@ def __index__(self):
13491349
self.assertEqual(list(islice(range(100), IntLike(10), IntLike(50), IntLike(5))),
13501350
list(range(10,50,5)))
13511351

1352-
# TODO: RUSTPYTHON
1353-
@unittest.expectedFailure
13541352
def test_takewhile(self):
13551353
data = [1, 3, 5, 20, 2, 4, 6, 8]
13561354
self.assertEqual(list(takewhile(underten, data)), [1, 3, 5])

vm/src/stdlib/itertools.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,15 @@ mod decl {
467467
}
468468

469469
#[pyclass(with(IterNext, Constructor), flags(BASETYPE))]
470-
impl PyItertoolsTakewhile {}
470+
impl PyItertoolsTakewhile {
471+
#[pymethod(magic)]
472+
fn reduce(zelf: PyRef<Self>) -> (PyTypeRef, (PyObjectRef, PyIter)) {
473+
(
474+
zelf.class().clone(),
475+
(zelf.predicate.clone(), zelf.iterable.clone()),
476+
)
477+
}
478+
}
471479
impl IterNextIterable for PyItertoolsTakewhile {}
472480
impl IterNext for PyItertoolsTakewhile {
473481
fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {

0 commit comments

Comments
 (0)