-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
__eq__ and __ne__ are implemented incorrectly for all classes #3455
Comments
Thanks @remcohaszing for taking the time to report this! As of 5e86158 it seems to impact 5 subpackages:
Unfortunately, it's spread out in an ad-hoc way so fixing everything will take awhile:
|
@remcohaszing Sanity check: Should the |
@lukesneeringer You're right, my mistake. |
@dhermes Should I hold off on this then? I was going to knock them all out. |
No, go for it. I was just giving you an example of the "correct" thing. Any time I've "done the right thing" was for new code. |
Okay, that was what I thought, but I wanted to be polite. |
__eq__
and__ne__
are implemented incorrectly throughout the entiregoogle-cloud-*
code base. I encountered this issue when trying to compare agoogle.cloud.datastore.Key
instance tounittest.mock.ANY
.When implementing custom equality in Python (2 or 3), it should be written like this:
Throughout the entire code base of this repository, equality is implemented like this:
As a result gcloud instances can never equal entities of other classes if they are the first object in the comparison. This is not an issue for most cases, but there are cases where this is an issue. Also this behaviour is simply incorrect.
The
__ne__
implementation works, because__eq__
is implemented incorrectly. The boolean value ofNotImplemented
isTrue
.This is typically an issue when unittesting.
The text was updated successfully, but these errors were encountered: