Skip to content

Commit

Permalink
Fix Message equality comparison (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew authored Jul 29, 2023
1 parent 6faac1d commit 4cdf1bb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/betterproto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ def __raw_get(self, name: str) -> Any:

def __eq__(self, other) -> bool:
if type(self) is not type(other):
return False
return NotImplemented

for field_name in self._betterproto.meta_by_field_name:
self_val = self.__raw_get(field_name)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
List,
Optional,
)
from unittest.mock import ANY

import pytest

Expand Down Expand Up @@ -727,3 +728,15 @@ class Spam(betterproto.Message):
assert not Spam().is_set("bar")
assert Spam(foo=True).is_set("foo")
assert Spam(foo=True, bar=0).is_set("bar")


def test_equality_comparison():
from tests.output_betterproto.bool import Test as TestMessage

msg = TestMessage(value=True)

assert msg == msg
assert msg == ANY
assert msg == TestMessage(value=True)
assert msg != 1
assert msg != TestMessage(value=False)

0 comments on commit 4cdf1bb

Please sign in to comment.