Browse Source

Fix GuildFolder typings

pull/10109/head
dolfies 3 years ago
parent
commit
3f89148147
  1. 41
      discord/guild_folder.py

41
discord/guild_folder.py

@ -46,21 +46,15 @@ class GuildFolder:
.. note:: .. note::
Guilds not in folders *are* actually in folders API wise, with them being the only member. Guilds not in folders *are* actually in folders API wise, with them being the only member.
Because Discord.
.. container:: operations These folders do not have an ID or name.
.. describe:: x == y
Checks if two guild folders are equal.
.. describe:: x != y
Checks if two guild folders are not equal. .. versionadded:: 1.9
.. describe:: hash(x) .. versionchanged:: 2.0
Removed various operations and made ``id`` and ``name`` optional.
Return the folder's hash. .. container:: operations
.. describe:: str(x) .. describe:: str(x)
@ -72,9 +66,9 @@ class GuildFolder:
Attributes Attributes
---------- ----------
id: Union[:class:`str`, :class:`int`] id: Optional[Union[:class:`str`, :class:`int`]]
The ID of the folder. The ID of the folder.
name: :class:`str` name: Optional[:class:`str`]
The name of the folder. The name of the folder.
guilds: List[:class:`Guild`] guilds: List[:class:`Guild`]
The guilds in the folder. The guilds in the folder.
@ -84,27 +78,16 @@ class GuildFolder:
def __init__(self, *, data, state: ConnectionState) -> None: def __init__(self, *, data, state: ConnectionState) -> None:
self._state = state self._state = state
self.id: Snowflake = data['id'] self.id: Optional[Snowflake] = data['id']
self.name: str = data['name'] self.name: Optional[str] = data['name']
self._colour: int = data['color'] self._colour: Optional[int] = data['color']
self.guilds: List[Guild] = list(filter(None, map(self._get_guild, data['guild_ids']))) # type: ignore # Lying for better developer UX self.guilds: List[Guild] = list(filter(None, map(self._get_guild, data['guild_ids']))) # type: ignore # Lying for better developer UX
def __str__(self) -> str: def __str__(self) -> str:
return self.name or 'None' return self.name or ', '.join(guild.name for guild in self.guilds)
def __repr__(self) -> str: def __repr__(self) -> str:
return f'<GuildFolder id={self.id} name={self.name} guilds={self.guilds!r}>' return f'<GuildFolder id={self.id} name={self.name!r} guilds={self.guilds!r}>'
def __eq__(self, other) -> bool:
return isinstance(other, GuildFolder) and self.id == other.id
def __ne__(self, other) -> bool:
if isinstance(other, GuildFolder):
return self.id != other.id
return True
def __hash__(self) -> int:
return hash(self.id)
def __len__(self) -> int: def __len__(self) -> int:
return len(self.guilds) return len(self.guilds)

Loading…
Cancel
Save