Skip to content

[RFC] Add itertools.pairwise() #2351

Description

@darleybarreto

Summary

To keep up-to-date with CPython's implementation for 3.10, we should add itertools.pairwise().

Detailed Explanation

Looking at vm/src/stdlib/itertools.rs, it seems that we need something like

#[pyattr]
#[pyclass(name = "pairwise")]
#[derive(Debug)]
struct PyItertoolsPairwise {
    ...
}

impl PyValue for PyItertoolsPairwise {
    fn class(_vm: &VirtualMachine) -> &PyTypeRef {
        Self::static_type()
    }
}

#[pyimpl(with(PyIter))]
impl PyItertoolsPairwise {
    #[pyslot]
    fn tp_new(
        cls: PyTypeRef,
        iterable: PyObjectRef,
        vm: &VirtualMachine,
    ) -> PyResult<PyRef<Self>> {
        ...
        PyItertoolsPairwise {
            ...
        }
        .into_ref_with_type(vm, cls)
    }
}

impl PyIter for PyItertoolsPairwise {
    fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
        ...
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCRequest for comments

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions