Change certain sequences to use a special proxy type instead of list

This is to speed up cases where someone is just querying the length
of the underlying sequence. If anything else is done to the sequence
then it is copied from the original iterator.

This change should be mostly transparent.
This commit is contained in:
Rapptz
2022-07-19 01:31:33 -04:00
parent 98c4f2ae8b
commit 87bc79e6e3
6 changed files with 75 additions and 45 deletions

View File

@ -370,18 +370,18 @@ class Client:
return self._connection.user
@property
def guilds(self) -> List[Guild]:
"""List[:class:`.Guild`]: The guilds that the connected client is a member of."""
def guilds(self) -> Sequence[Guild]:
"""Sequence[:class:`.Guild`]: The guilds that the connected client is a member of."""
return self._connection.guilds
@property
def emojis(self) -> List[Emoji]:
"""List[:class:`.Emoji`]: The emojis that the connected client has."""
def emojis(self) -> Sequence[Emoji]:
"""Sequence[:class:`.Emoji`]: The emojis that the connected client has."""
return self._connection.emojis
@property
def stickers(self) -> List[GuildSticker]:
"""List[:class:`.GuildSticker`]: The stickers that the connected client has.
def stickers(self) -> Sequence[GuildSticker]:
"""Sequence[:class:`.GuildSticker`]: The stickers that the connected client has.
.. versionadded:: 2.0
"""
@ -396,8 +396,8 @@ class Client:
return utils.SequenceProxy(self._connection._messages or [])
@property
def private_channels(self) -> List[PrivateChannel]:
"""List[:class:`.abc.PrivateChannel`]: The private channels that the connected client is participating on.
def private_channels(self) -> Sequence[PrivateChannel]:
"""Sequence[:class:`.abc.PrivateChannel`]: The private channels that the connected client is participating on.
.. note::