Skip to content

Commit

Permalink
feat: add __eq__ to Snowflake (#641)
Browse files Browse the repository at this point in the history
* feat: add `__eq__` to Snowflake

* chore: remove outdated comments
  • Loading branch information
Catalyst4222 committed Mar 14, 2022
1 parent d43e8dc commit 63656b7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions interactions/api/models/misc.py
Expand Up @@ -166,9 +166,15 @@ def timestamp(self) -> datetime.datetime:
def __hash__(self):
return hash(self._snowflake)

# Do we need not equals, equals, gt/lt/ge/le?
# If so, list them under. By Discord API this may not be needed
# but end users might.
def __eq__(self, other):
if isinstance(other, Snowflake):
return str(self) == str(other)
elif isinstance(other, int):
return int(self) == other
elif isinstance(other, str):
return str(self) == other

return NotImplemented


class Color(object):
Expand Down
1 change: 1 addition & 0 deletions interactions/api/models/misc.pyi
Expand Up @@ -42,6 +42,7 @@ class Snowflake(object):
def __hash__(self) -> int: ...
def __str__(self) -> str: ...
def __int__(self) -> int: ...
def __eq__(self, other) -> Union[bool, NotImplemented]: ...

class Format:
USER: str
Expand Down

0 comments on commit 63656b7

Please sign in to comment.