Make Attachment hashable and castable to str
This commit is contained in:
parent
5a93e80e87
commit
5cb5126548
@ -68,9 +68,30 @@ def convert_emoji_reaction(emoji):
|
|||||||
|
|
||||||
raise InvalidArgument('emoji argument must be str, Emoji, or Reaction not {.__class__.__name__}.'.format(emoji))
|
raise InvalidArgument('emoji argument must be str, Emoji, or Reaction not {.__class__.__name__}.'.format(emoji))
|
||||||
|
|
||||||
class Attachment:
|
class Attachment(Hashable):
|
||||||
"""Represents an attachment from Discord.
|
"""Represents an attachment from Discord.
|
||||||
|
|
||||||
|
.. container:: operations
|
||||||
|
|
||||||
|
.. describe:: str(x)
|
||||||
|
|
||||||
|
Returns the URL of the attachment.
|
||||||
|
|
||||||
|
.. describe:: x == y
|
||||||
|
|
||||||
|
Checks if the attachment is equal to another attachment.
|
||||||
|
|
||||||
|
.. describe:: x != y
|
||||||
|
|
||||||
|
Checks if the attachment is not equal to another attachment.
|
||||||
|
|
||||||
|
.. describe:: hash(x)
|
||||||
|
|
||||||
|
Returns the hash of the attachment.
|
||||||
|
|
||||||
|
.. versionchanged:: 1.7
|
||||||
|
Attachment can now be casted to :class:`str` and is hashable.
|
||||||
|
|
||||||
Attributes
|
Attributes
|
||||||
------------
|
------------
|
||||||
id: :class:`int`
|
id: :class:`int`
|
||||||
@ -111,6 +132,9 @@ class Attachment:
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<Attachment id={0.id} filename={0.filename!r} url={0.url!r}>'.format(self)
|
return '<Attachment id={0.id} filename={0.filename!r} url={0.url!r}>'.format(self)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.url or ''
|
||||||
|
|
||||||
async def save(self, fp, *, seek_begin=True, use_cached=False):
|
async def save(self, fp, *, seek_begin=True, use_cached=False):
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user