Skip to content

add an impl_eq! macro that implements __richcmp__ #20

@MarquessV

Description

@MarquessV

For types that implement PartialEq/Eq, Python's __richcmp__ dunder method is easily defined as:

#[pymethods]
impl PyType {
    pub fn __richcmp__(&self, py: Python<'_>, other: &Self, op: CompareOp) -> PyObject {
        match op {
            CompareOp::Eq => (self.as_inner() == other.as_inner()).into_py(py),
            _ => py.NotImplemented(),
        }
    }
}

An impl_eq! macro would be a nice addition to handle this case. The overlap with impl_compare! would have to be well documented to avoid confusion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions