Fix Message equality comparison (#513)

This commit is contained in:
Andrew 2023-07-29 14:06:56 +03:00 committed by GitHub
parent 6faac1d1ca
commit 4cdf1bb9e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -651,7 +651,7 @@ class Message(ABC):
def __eq__(self, other) -> bool: def __eq__(self, other) -> bool:
if type(self) is not type(other): if type(self) is not type(other):
return False return NotImplemented
for field_name in self._betterproto.meta_by_field_name: for field_name in self._betterproto.meta_by_field_name:
self_val = self.__raw_get(field_name) self_val = self.__raw_get(field_name)

View File

@ -18,6 +18,7 @@ from typing import (
List, List,
Optional, Optional,
) )
from unittest.mock import ANY
import pytest import pytest
@ -727,3 +728,15 @@ def test_is_set():
assert not Spam().is_set("bar") assert not Spam().is_set("bar")
assert Spam(foo=True).is_set("foo") assert Spam(foo=True).is_set("foo")
assert Spam(foo=True, bar=0).is_set("bar") 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)