Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add __eq__ to Snowflake #641

Merged
merged 2 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions interactions/api/models/misc.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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