Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an impl_eq! macro that implements __richcmp__ #20

Open
MarquessV opened this issue Mar 15, 2023 · 0 comments
Open

add an impl_eq! macro that implements __richcmp__ #20

MarquessV opened this issue Mar 15, 2023 · 0 comments

Comments

@MarquessV
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant