Skip to content

Commit 9402938

Browse files
LucaSforzayouknowone
authored andcommitted
added __reduce__ method for itertools.permutations
1 parent d5a6284 commit 9402938

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

vm/src/stdlib/itertools.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,15 @@ mod decl {
16701670
}
16711671

16721672
#[pyclass(with(IterNext, Iterable, Constructor))]
1673-
impl PyItertoolsPermutations {}
1673+
impl PyItertoolsPermutations {
1674+
#[pymethod(magic)]
1675+
fn reduce(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyRef<PyTuple> {
1676+
vm.new_tuple((
1677+
zelf.class().to_owned(),
1678+
vm.new_tuple((zelf.pool.clone(), vm.ctx.new_int(zelf.r.load()))),
1679+
))
1680+
}
1681+
}
16741682
impl SelfIter for PyItertoolsPermutations {}
16751683
impl IterNext for PyItertoolsPermutations {
16761684
fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {

0 commit comments

Comments
 (0)