mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-16 10:49:24 +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:
|
def __getattr__(self, attr: str) -> None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def __eq__(self, other: object) -> bool:
|
||||||
|
return isinstance(other, EmbedProxy) and self.__dict__ == other.__dict__
|
||||||
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from typing_extensions import Self
|
from typing_extensions import Self
|
||||||
@ -106,6 +109,12 @@ class Embed:
|
|||||||
|
|
||||||
.. versionadded:: 2.0
|
.. 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
|
For ease of use, all parameters that expect a :class:`str` are implicitly
|
||||||
casted to :class:`str` for you.
|
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
|
@property
|
||||||
def colour(self) -> Optional[Colour]:
|
def colour(self) -> Optional[Colour]:
|
||||||
return getattr(self, '_colour', None)
|
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``.
|
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.
|
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``.
|
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
|
.. code-block:: python
|
||||||
|
|
||||||
# before
|
# before
|
||||||
embed = discord.Embed(title='foo')
|
embed = discord.Embed(title='foo')
|
||||||
embed.title = discord.Embed.Empty
|
embed.title = discord.Embed.Empty
|
||||||
|
embed == embed.copy() # False
|
||||||
|
|
||||||
# after
|
# after
|
||||||
embed = discord.Embed(title='foo')
|
embed = discord.Embed(title='foo')
|
||||||
embed.title = None
|
embed.title = None
|
||||||
|
embed == embed.copy() # True
|
||||||
|
{embed, embed} # Raises TypeError
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Removal of ``InvalidArgument`` Exception
|
Removal of ``InvalidArgument`` Exception
|
||||||
|
Loading…
x
Reference in New Issue
Block a user