mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-04 08:56:19 +00:00
Use a specific tag type for member and user comparisons
The previous protocol based tag type caused significant overhead (in the magnitude of seconds). Removing this should simplify object creation by removing typing.Generic from the __mro__
This commit is contained in:
@ -35,10 +35,13 @@ __all__ = (
|
||||
'ClientUser',
|
||||
)
|
||||
|
||||
_BaseUser = discord.abc.User
|
||||
|
||||
class _UserTag:
|
||||
__slots__ = ()
|
||||
id: int
|
||||
|
||||
|
||||
class BaseUser(_BaseUser):
|
||||
class BaseUser(_UserTag):
|
||||
__slots__ = ('name', 'id', 'discriminator', '_avatar', 'bot', 'system', '_public_flags', '_state')
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@ -62,7 +65,7 @@ class BaseUser(_BaseUser):
|
||||
return f'{self.name}#{self.discriminator}'
|
||||
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, _BaseUser) and other.id == self.id
|
||||
return isinstance(other, _UserTag) and other.id == self.id
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
@ -118,6 +121,7 @@ class BaseUser(_BaseUser):
|
||||
return Asset._from_default_avatar(self._state, int(self.discriminator) % len(DefaultAvatar))
|
||||
else:
|
||||
return Asset._from_avatar(self._state, self.id, self._avatar)
|
||||
|
||||
@property
|
||||
def default_avatar(self):
|
||||
""":class:`Asset`: Returns the default avatar for a given user. This is calculated by the user's discriminator."""
|
||||
@ -247,7 +251,7 @@ class ClientUser(BaseUser):
|
||||
self._flags = data.get('flags', 0)
|
||||
self.mfa_enabled = data.get('mfa_enabled', False)
|
||||
|
||||
async def edit(self, *, username: str = MISSING, avatar: bytes = MISSING) -> None:
|
||||
async def edit(self, *, username: str = MISSING, avatar: bytes = MISSING) -> None:
|
||||
"""|coro|
|
||||
|
||||
Edits the current profile of the client.
|
||||
|
Reference in New Issue
Block a user