Skip to content

Commit 63656b7

Browse files
authored
feat: add __eq__ to Snowflake (#641)
* feat: add `__eq__` to Snowflake * chore: remove outdated comments
1 parent d43e8dc commit 63656b7

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

interactions/api/models/misc.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,15 @@ def timestamp(self) -> datetime.datetime:
166166
def __hash__(self):
167167
return hash(self._snowflake)
168168

169-
# Do we need not equals, equals, gt/lt/ge/le?
170-
# If so, list them under. By Discord API this may not be needed
171-
# but end users might.
169+
def __eq__(self, other):
170+
if isinstance(other, Snowflake):
171+
return str(self) == str(other)
172+
elif isinstance(other, int):
173+
return int(self) == other
174+
elif isinstance(other, str):
175+
return str(self) == other
176+
177+
return NotImplemented
172178

173179

174180
class Color(object):

interactions/api/models/misc.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Snowflake(object):
4242
def __hash__(self) -> int: ...
4343
def __str__(self) -> str: ...
4444
def __int__(self) -> int: ...
45+
def __eq__(self, other) -> Union[bool, NotImplemented]: ...
4546

4647
class Format:
4748
USER: str

0 commit comments

Comments
 (0)