Add Rich Equality Comparison to WriteAccessAllowed (#3911)

This commit is contained in:
Bibo-Joshi 2023-10-02 20:21:51 +02:00 committed by GitHub
parent 895403a0b5
commit 39d45124df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View file

@ -28,7 +28,12 @@ class WriteAccessAllowed(TelegramObject):
This object represents a service message about a user allowing a bot to write messages after
adding the bot to the attachment menu or launching a Web App from a link.
Objects of this class are comparable in terms of equality. Two objects of this class are
considered equal, if their :attr:`web_app_name` is equal.
.. versionadded:: 20.0
.. versionchanged:: NEXT.VERSION
Added custom equality comparison for objects of this class.
Args:
web_app_name (:obj:`str`, optional): Name of the Web App which was launched from a link.
@ -50,4 +55,6 @@ class WriteAccessAllowed(TelegramObject):
super().__init__(api_kwargs=api_kwargs)
self.web_app_name: Optional[str] = web_app_name
self._id_attrs = (self.web_app_name,)
self._freeze()

View file

@ -36,3 +36,22 @@ class TestWriteAccessAllowed:
action = WriteAccessAllowed()
action_dict = action.to_dict()
assert action_dict == {}
def test_equality(self):
a = WriteAccessAllowed()
b = WriteAccessAllowed()
c = WriteAccessAllowed(web_app_name="foo")
d = WriteAccessAllowed(web_app_name="foo")
e = WriteAccessAllowed(web_app_name="bar")
assert a == b
assert hash(a) == hash(b)
assert a != c
assert hash(a) != hash(c)
assert c == d
assert hash(c) == hash(d)
assert c != e
assert hash(c) != hash(e)