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

Don't raise TypeError from generated equality method #4287

Merged
merged 2 commits into from
Jun 26, 2024

Conversation

jatoben
Copy link
Contributor

@jatoben jatoben commented Jun 25, 2024

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
Copy link
Contributor

alex commented Jun 26, 2024

This makes sense and looks right to me.

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I found the same issue and hadn't had a chance to investigate / report yet 😅

@davidhewitt davidhewitt added this pull request to the merge queue Jun 26, 2024
Merged via the queue into PyO3:main with commit 7c2f5e8 Jun 26, 2024
41 checks passed
@jatoben jatoben deleted the type-equality branch June 26, 2024 16:21
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

Successfully merging this pull request may close these issues.

3 participants