From 164e343517a52bcfa82f0f5c8d2d8815fc0c2ac8 Mon Sep 17 00:00:00 2001 From: dvermd <315743+dvermd@users.noreply.github.com> Date: Sat, 1 Oct 2022 15:23:18 +0200 Subject: [PATCH] add takewhile.__reduce__ --- Lib/test/test_itertools.py | 2 -- vm/src/stdlib/itertools.rs | 10 +++++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index 3530fc6c535..53cc26355b3 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -1349,8 +1349,6 @@ def __index__(self): 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]) diff --git a/vm/src/stdlib/itertools.rs b/vm/src/stdlib/itertools.rs index 9ccdb2c3991..ddb976590e7 100644 --- a/vm/src/stdlib/itertools.rs +++ b/vm/src/stdlib/itertools.rs @@ -467,7 +467,15 @@ mod decl { } #[pyclass(with(IterNext, Constructor), flags(BASETYPE))] - impl PyItertoolsTakewhile {} + impl PyItertoolsTakewhile { + #[pymethod(magic)] + fn reduce(zelf: PyRef) -> (PyTypeRef, (PyObjectRef, PyIter)) { + ( + zelf.class().clone(), + (zelf.predicate.clone(), zelf.iterable.clone()), + ) + } + } impl IterNextIterable for PyItertoolsTakewhile {} impl IterNext for PyItertoolsTakewhile { fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult {