PyO3 / pyo3

Rust bindings for the Python interpreter
https://pyo3.rs
Other
11.44k stars 693 forks source link

Don't raise `TypeError` from generated equality method #4287

Closed jatoben closed 1 week ago

jatoben commented 1 week ago

While updating a project to replace manually-written __eq__() methods with the new #[pyclass(eq)] option added in 0.22, I found that doing so causes a TypeError to be raised when objects of different types are checked for equality. I believe it should return NotImplemented instead, to stay consistent with pyclasses that use __eq__() and standard Python types.

This PR contains the change, and a test to confirm the comparison behavior.

Please let me know how this looks, particularly the tests -- I'm not sure if I got those in the right spot 🙂 Thanks!

alex commented 1 week ago

This makes sense and looks right to me.