Skip to content

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

Merged
merged 7 commits into from
Mar 3, 2024

Conversation

Gouvernathor
Copy link
Contributor

@Gouvernathor Gouvernathor commented Oct 11, 2023

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/

Copy link
Contributor

@skirpichev skirpichev left a 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.

@Gouvernathor
Copy link
Contributor Author

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.

Copy link
Member

@carljm carljm left a 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.)

@erlend-aasland erlend-aasland enabled auto-merge (squash) March 3, 2024 00:41
@erlend-aasland erlend-aasland merged commit 67f742e into python:main Mar 3, 2024
@miss-islington-app
Copy link

Thanks @Gouvernathor for the PR, and @erlend-aasland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 3, 2024
pythonGH-110729)

(cherry picked from commit 67f742e)

Co-authored-by: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented Mar 3, 2024

GH-116254 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Mar 3, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 3, 2024
pythonGH-110729)

(cherry picked from commit 67f742e)

Co-authored-by: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented Mar 3, 2024

GH-116255 is a backport of this pull request to the 3.11 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.11 only security fixes label Mar 3, 2024
erlend-aasland pushed a commit that referenced this pull request Mar 3, 2024
…ty (GH-110729) (#116254)

(cherry picked from commit 67f742e)

Co-authored-by: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com>
erlend-aasland pushed a commit that referenced this pull request Mar 3, 2024
…ty (GH-110729) (#116255)

(cherry picked from commit 67f742e)

Co-authored-by: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com>
woodruffw pushed a commit to woodruffw-forks/cpython that referenced this pull request Mar 4, 2024
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 25, 2024
@Gouvernathor Gouvernathor deleted the patch-7 branch April 14, 2024 17:04
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants