-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Comparing a proto message with an object of unknown returns NotImplem…
…ented The Python comparison protocol requires that if an object doesn't know how to compare itself to an object of a different type, it returns NotImplemented rather than False. The interpreter will then try performing the comparison using the other operand. This translates, for protos, to: If a proto message doesn't know how to compare itself to an object of non-message type, it returns NotImplemented. This way, the interpreter will then try performing the comparison using the comparison methods of the other object, which may know how to compare itself to a message. If not, then Python will return the combined result (e.g., if both objects don't know how to perform __eq__, then the equality operator `==` return false). This change allows one to compare a proto with custom matchers such as mock.ANY that the message doesn't know how to compare to, regardless of whether mock.ANY is on the right-hand side or left-hand side of the equality (prior to this change, it only worked with mock.ANY on the left-hand side). Fixes #9173 PiperOrigin-RevId: 561728156
- Loading branch information
1 parent
14222b3
commit 12d4f41
Showing
3 changed files
with
56 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters