From 852699500453ea9565ec5d678e99a49bf64c2395 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Thu, 18 May 2017 05:15:06 -0400 Subject: [PATCH] Minor speedup when doing comparisons. Shred 2 getattr calls + 1 global lookup to 1 global lookup. --- discord/member.py | 6 ++++-- discord/user.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/discord/member.py b/discord/member.py index 7e4c4069a..a91f60d10 100644 --- a/discord/member.py +++ b/discord/member.py @@ -106,8 +106,10 @@ def flatten_user(cls): return cls +_BaseUser = discord.abc.User + @flatten_user -class Member(discord.abc.Messageable, discord.abc.User): +class Member(discord.abc.Messageable, _BaseUser): """Represents a Discord member to a :class:`Guild`. This implements a lot of the functionality of :class:`User`. @@ -170,7 +172,7 @@ class Member(discord.abc.Messageable, discord.abc.User): ' bot={1.bot} nick={0.nick!r} guild={0.guild!r}>'.format(self, self._user) def __eq__(self, other): - return isinstance(other, discord.abc.User) and other.id == self.id + return isinstance(other, _BaseUser) and other.id == self.id def __ne__(self, other): return not self.__eq__(other) diff --git a/discord/user.py b/discord/user.py index e5cb8f5f4..e078bc3d3 100644 --- a/discord/user.py +++ b/discord/user.py @@ -35,7 +35,9 @@ import asyncio Profile = namedtuple('Profile', 'premium user mutual_guilds connected_accounts premium_since') -class BaseUser(discord.abc.User): +_BaseUser = discord.abc.User + +class BaseUser(_BaseUser): __slots__ = ('name', 'id', 'discriminator', 'avatar', 'bot', '_state') def __init__(self, *, state, data): @@ -50,7 +52,7 @@ class BaseUser(discord.abc.User): return '{0.name}#{0.discriminator}'.format(self) def __eq__(self, other): - return isinstance(other, discord.abc.User) and other.id == self.id + return isinstance(other, _BaseUser) and other.id == self.id def __ne__(self, other): return not self.__eq__(other)