8000 Add Rich Equality Comparison to `WriteAccessAllowed` (#3911) · guillemap/python-telegram-bot@39d4512 · GitHub
[go: up one dir, main page]

Skip to content

Commit 39d4512

Browse files
authored
Add Rich Equality Comparison to WriteAccessAllowed (python-telegram-bot#3911)
1 parent 895403a commit 39d4512

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

telegram/_writeaccessallowed.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ class WriteAccessAllowed(TelegramObject):
2828
This object represents a service message about a user allowing a bot to write messages after
2929
adding the bot to the attachment menu or launching a Web App from a link.
3030
31+
Objects of this class are comparable in terms of equality. Two objects of this class are
32+
considered equal, if their :attr:`web_app_name` is equal.
33+
3134
.. versionadded:: 20.0
35+
.. versionchanged:: NEXT.VERSION
36+
Added custom equality comparison for objects of this class.
3237
3338
Args:
3439
web_app_name (:obj:`str`, optional): Name of the Web App which was launched from a link.
@@ -50,4 +55,6 @@ def __init__(
5055
super().__init__(api_kwargs=api_kwargs)
5156
self.web_app_name: Optional[str] = web_app_name
5257

58+
self._id_attrs = (self.web_app_name,)
59+
5360
self._freeze()

tests/test_writeaccessallowed.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,22 @@ def test_to_dict(self):
3636
action = WriteAccessAllowed()
3737
action_dict = action.to_dict()
3838
assert action_dict == {}
39+
40+
def test_equality(self):
41+
a = WriteAccessAllowed()
42+
b = WriteAccessAllowed()
43+
c = WriteAccessAllowed(web_app_name="foo")
44+
d = WriteAccessAllowed(web_app_name="foo")
45+
e = WriteAccessAllowed(web_app_name="bar")
46+
47+
assert a == b
48+
assert hash(a) == hash(b)
49+
50+
assert a != c
51+
assert hash(a) != hash(c)
52+
53+
assert c == d
54+
assert hash(c) == hash(d)
55+
56+
assert c != e
57+
assert hash(c) != hash(e)

0 commit comments

Comments
 (0)
0