Skip to content

Commit 4cdf1bb

Browse files
author
Andrew
authored
Fix Message equality comparison (#513)
1 parent 6faac1d commit 4cdf1bb

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/betterproto/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ def __raw_get(self, name: str) -> Any:
651651

652652
def __eq__(self, other) -> bool:
653653
if type(self) is not type(other):
654-
return False
654+
return NotImplemented
655655

656656
for field_name in self._betterproto.meta_by_field_name:
657657
self_val = self.__raw_get(field_name)

tests/test_features.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
List,
1919
Optional,
2020
)
21+
from unittest.mock import ANY
2122

2223
import pytest
2324

@@ -727,3 +728,15 @@ class Spam(betterproto.Message):
727728
assert not Spam().is_set("bar")
728729
assert Spam(foo=True).is_set("foo")
729730
assert Spam(foo=True, bar=0).is_set("bar")
731+
732+
733+
def test_equality_comparison():
734+
from tests.output_betterproto.bool import Test as TestMessage
735+
736+
msg = TestMessage(value=True)
737+
738+
assert msg == msg
739+
assert msg == ANY
740+
assert msg == TestMessage(value=True)
741+
assert msg != 1
742+
assert msg != TestMessage(value=False)

0 commit comments

Comments
 (0)