Skip to content

Commit

Permalink
Change Embed.fields to always return a list (#1287)
Browse files Browse the repository at this point in the history
* Change embed.fields to always return a list

* Update embeds.py to remove try block from clear_fields, now that _fields won't ever return an AttributeError

Co-authored-by: krittick <ben@krittick.net>
  • Loading branch information
plun1331 and krittick authored Apr 24, 2022
1 parent 8b0d230 commit 223616f
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions discord/embeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,17 +668,14 @@ def remove_author(self: E) -> E:
return self

@property
def fields(self) -> Optional[List[EmbedField]]:
def fields(self) -> List[EmbedField]:
"""Returns a :class:`list` of :class:`EmbedField` objects denoting the field contents.
See :meth:`add_field` for possible values you can access.
If the attribute has no value then ``None`` is returned.
"""
if self._fields:
return self._fields
else:
return None
return self._fields

@fields.setter
def fields(self, value: List[EmbedField]) -> None:
Expand All @@ -692,9 +689,7 @@ def fields(self, value: List[EmbedField]) -> None:
if not all(isinstance(x, EmbedField) for x in value):
raise TypeError("Expected a list of EmbedField objects.")

self.clear_fields()
for field in value:
self.add_field(name=field.name, value=field.value, inline=field.inline)
self._fields = value

def append_field(self, field: EmbedField) -> None:
"""Appends an :class:`EmbedField` object to the embed.
Expand Down Expand Up @@ -762,10 +757,7 @@ def insert_field_at(self: E, index: int, *, name: Any, value: Any, inline: bool

def clear_fields(self) -> None:
"""Removes all fields from this embed."""
try:
self._fields.clear()
except AttributeError:
self._fields = []
self._fields.clear()

def remove_field(self, index: int) -> None:
"""Removes a field at a specified index.
Expand Down

0 comments on commit 223616f

Please sign in to comment.