Skip to content

Commit 6d552f1

Browse files
committed
style(typing): Typehint reaction.py
Signed-off-by: Mathieu Corsham <[email protected]>
1 parent dc1a586 commit 6d552f1

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

discord/reaction.py

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,28 @@
2323
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2424
DEALINGS IN THE SOFTWARE.
2525
"""
26+
from __future__ import annotations
27+
28+
from typing import (
29+
Optional,
30+
TYPE_CHECKING,
31+
Union,
32+
)
33+
34+
if TYPE_CHECKING:
35+
from .types.message import Reaction as ReactionPayload
36+
from .message import Message
37+
from .emoji import Emoji
38+
from .partial_emoji import PartialEmoji
39+
from .abc import Snowflake
2640

2741
from .iterators import ReactionIterator
2842

43+
2944
class Reaction:
3045
"""Represents a reaction to a message.
3146
32-
Depending on the way this object was created, some of the attributes can
47+
Depending on the way this object was created, some attributes can
3348
have a value of ``None``.
3449
3550
.. container:: operations
@@ -55,7 +70,7 @@ class Reaction:
5570
Attributes
5671
-----------
5772
emoji: Union[:class:`Emoji`, :class:`PartialEmoji`, :class:`str`]
58-
The reaction emoji. May be a custom emoji, or a unicode emoji.
73+
The reaction emoji. Might be a custom emoji, or a unicode emoji.
5974
count: :class:`int`
6075
Number of times this reaction was made
6176
me: :class:`bool`
@@ -65,35 +80,35 @@ class Reaction:
6580
"""
6681
__slots__ = ('message', 'count', 'emoji', 'me')
6782

68-
def __init__(self, *, message, data, emoji=None):
69-
self.message = message
70-
self.emoji = emoji or message._state.get_reaction_emoji(data['emoji'])
71-
self.count = data.get('count', 1)
72-
self.me = data.get('me')
83+
def __init__(self, *, message: Message, data: ReactionPayload, emoji: Optional[Union[Emoji, PartialEmoji, str]] = None):
84+
self.message: Message = message
85+
self.emoji: Union[Emoji, PartialEmoji, str] = emoji or message._state.get_reaction_emoji(data['emoji'])
86+
self.count: int = data.get('count', 1)
87+
self.me: bool = data.get('me')
7388

7489
@property
75-
def custom_emoji(self):
90+
def custom_emoji(self) -> bool:
7691
""":class:`bool`: If this is a custom emoji."""
7792
return not isinstance(self.emoji, str)
7893

79-
def __eq__(self, other):
94+
def __eq__(self, other) -> bool:
8095
return isinstance(other, self.__class__) and other.emoji == self.emoji
8196

82-
def __ne__(self, other):
97+
def __ne__(self, other) -> bool:
8398
if isinstance(other, self.__class__):
8499
return other.emoji != self.emoji
85100
return True
86101

87-
def __hash__(self):
102+
def __hash__(self) -> int:
88103
return hash(self.emoji)
89104

90-
def __str__(self):
105+
def __str__(self) -> str:
91106
return str(self.emoji)
92107

93-
def __repr__(self):
108+
def __repr__(self) -> str:
94109
return '<Reaction emoji={0.emoji!r} me={0.me} count={0.count}>'.format(self)
95110

96-
async def remove(self, user):
111+
async def remove(self, user: Snowflake) -> None:
97112
"""|coro|
98113
99114
Remove the reaction by the provided :class:`User` from the message.
@@ -121,7 +136,7 @@ async def remove(self, user):
121136

122137
await self.message.remove_reaction(self.emoji, user)
123138

124-
async def clear(self):
139+
async def clear(self) -> None:
125140
"""|coro|
126141
127142
Clears this reaction from the message.
@@ -143,7 +158,7 @@ async def clear(self):
143158
"""
144159
await self.message.clear_reaction(self.emoji)
145160

146-
def users(self, limit=None, after=None):
161+
def users(self, limit: Optional[int] = None, after: Optional[Snowflake] = None) -> ReactionIterator:
147162
"""Returns an :class:`AsyncIterator` representing the users that have reacted to the message.
148163
149164
The ``after`` parameter must represent a member

0 commit comments

Comments
 (0)