mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-16 02:39:01 +00:00
Implement Embed.__eq__ and EmbedProxy.__eq__
This commit is contained in:
parent
9f1c511b47
commit
b80cb47caf
@ -51,6 +51,9 @@ class EmbedProxy:
|
||||
def __getattr__(self, attr: str) -> None:
|
||||
return None
|
||||
|
||||
def __eq__(self, other: object) -> bool:
|
||||
return isinstance(other, EmbedProxy) and self.__dict__ == other.__dict__
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing_extensions import Self
|
||||
@ -106,6 +109,12 @@ class Embed:
|
||||
|
||||
.. versionadded:: 2.0
|
||||
|
||||
.. describe:: x == y
|
||||
|
||||
Checks if two embeds are equal.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
|
||||
For ease of use, all parameters that expect a :class:`str` are implicitly
|
||||
casted to :class:`str` for you.
|
||||
|
||||
@ -281,6 +290,23 @@ class Embed:
|
||||
)
|
||||
)
|
||||
|
||||
def __eq__(self, other: Embed) -> bool:
|
||||
return isinstance(other, Embed) and (
|
||||
self.type == other.type
|
||||
and self.title == other.title
|
||||
and self.url == other.url
|
||||
and self.description == other.description
|
||||
and self.colour == other.colour
|
||||
and self.fields == other.fields
|
||||
and self.timestamp == other.timestamp
|
||||
and self.author == other.author
|
||||
and self.thumbnail == other.thumbnail
|
||||
and self.footer == other.footer
|
||||
and self.image == other.image
|
||||
and self.provider == other.provider
|
||||
and self.video == other.video
|
||||
)
|
||||
|
||||
@property
|
||||
def colour(self) -> Optional[Colour]:
|
||||
return getattr(self, '_colour', None)
|
||||
|
@ -883,22 +883,28 @@ The following properties were changed to return a sequence instead of a list:
|
||||
This change should be transparent, unless you are modifying the sequence by doing things such as ``list.append``.
|
||||
|
||||
|
||||
Removal of ``Embed.Empty``
|
||||
---------------------------
|
||||
Embed Changes
|
||||
--------------
|
||||
|
||||
Originally, embeds used a special sentinel to denote emptiness or remove an attribute from display. The ``Embed.Empty`` sentinel was made when Discord's embed design was in a nebulous state of flux. Since then, the embed design has stabilised and thus the sentinel is seen as legacy.
|
||||
|
||||
Therefore, ``Embed.Empty`` has been removed in favour of ``None``.
|
||||
|
||||
Additionally, ``Embed.__eq__`` has been implemented thus embeds becoming unhashable (e.g. using them in sets or dict keys).
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# before
|
||||
embed = discord.Embed(title='foo')
|
||||
embed.title = discord.Embed.Empty
|
||||
embed == embed.copy() # False
|
||||
|
||||
# after
|
||||
embed = discord.Embed(title='foo')
|
||||
embed.title = None
|
||||
embed == embed.copy() # True
|
||||
{embed, embed} # Raises TypeError
|
||||
|
||||
|
||||
|
||||
Removal of ``InvalidArgument`` Exception
|
||||
|
Loading…
x
Reference in New Issue
Block a user