From 3c387e90311af2f06d116bed02ed971f7dcba69f Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sat, 25 May 2019 03:14:35 -0400 Subject: [PATCH] Use attrgetter to speed up Member attribute access by 2x. --- discord/member.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/discord/member.py b/discord/member.py index 41cecb800..4901e7775 100644 --- a/discord/member.py +++ b/discord/member.py @@ -25,6 +25,7 @@ DEALINGS IN THE SOFTWARE. """ import itertools +from operator import attrgetter import discord.abc @@ -90,10 +91,12 @@ def flatten_user(cls): # if it's a slotted attribute or a property, redirect it # slotted members are implemented as member_descriptors in Type.__dict__ if not hasattr(value, '__annotations__'): - def getter(self, x=attr): - return getattr(self._user, x) + getter = attrgetter('_user.' + attr) setattr(cls, attr, property(getter, doc='Equivalent to :attr:`User.%s`' % attr)) else: + # Technically, this can also use attrgetter + # However I'm not sure how I feel about "functions" returning properties + # It probably breaks something in Sphinx. # probably a member function by now def generate_function(x): def general(self, *args, **kwargs):