Skip to content

Commit 93d731c

Browse files
authored
Merge pull request RustPython#5029 from LucaSforza/main
added __reduce__ method for itertools.permutations
2 parents d24013d + 9402938 commit 93d731c

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)