-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-72971: Clarify the special no-TypeError behavior for equality #110729
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, except maybe for note about TypeError
.
Note for reviewers : see the Shorten again commit. I removed that line because Skirpichev asked for that, but I'm not sold and I think it would make the explanation more clear, if a bit redundant. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks correct to me, and also necessary, in that it closes a gap in the specification where we should specify the behavior. (The alternative would be to say that the behavior of ==
when all relevant dunder methods return NotImplementedError
is implementation-defined, and I don't think that is desirable.)
Thanks @Gouvernathor for the PR, and @erlend-aasland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
pythonGH-110729) (cherry picked from commit 67f742e) Co-authored-by: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com>
GH-116254 is a backport of this pull request to the 3.12 branch. |
pythonGH-110729) (cherry picked from commit 67f742e) Co-authored-by: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com>
GH-116255 is a backport of this pull request to the 3.11 branch. |
Re:
https://discuss.python.org/t/notimplemented-and-operator-overloading/34935/
https://stackoverflow.com/questions/40780004/returning-notimplemented-from-eq
Math operators raise TypeErrors when the methods return NotImplemented and it is documented.
Comparison operators do the same but it was not explicitly written (even though it was heavily implied and understood).
Equality operators do not do that, and instead revert to non-overrideable operators. That was not documented, and troubled quite a number of people apparently.
📚 Documentation preview 📚: https://cpython-previews--110729.org.readthedocs.build/