aboutsummaryrefslogtreecommitdiff
path: root/discord/utils.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2016-01-06 23:40:20 -0500
committerRapptz <[email protected]>2016-01-06 23:40:20 -0500
commit89a418a3886d3a96cb77965eacdc1078dbb38dbf (patch)
tree780081950726e834a92b1178449ae5f3d814f578 /discord/utils.py
parent[commands] Don't skip whitespace if the command trigger is found. (diff)
downloaddiscord.py-89a418a3886d3a96cb77965eacdc1078dbb38dbf.tar.xz
discord.py-89a418a3886d3a96cb77965eacdc1078dbb38dbf.zip
Add __slots__ for missing classes that didn't have it.
Diffstat (limited to 'discord/utils.py')
-rw-r--r--discord/utils.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/discord/utils.py b/discord/utils.py
index 169bf1b1..5318b631 100644
--- a/discord/utils.py
+++ b/discord/utils.py
@@ -46,6 +46,28 @@ class cached_property:
return value
+class CachedSlotProperty:
+ def __init__(self, name, function):
+ self.name = name
+ self.function = function
+ self.__doc__ = getattr(function, '__doc__')
+
+ def __get__(self, instance, owner):
+ if instance is None:
+ return self
+
+ try:
+ return getattr(instance, self.name)
+ except AttributeError:
+ value = self.function(instance)
+ setattr(instance, self.name, value)
+ return value
+
+def cached_slot_property(name):
+ def decorator(func):
+ return CachedSlotProperty(name, func)
+ return decorator
+
def parse_time(timestamp):
if timestamp:
return datetime.datetime(*map(int, re_split(r'[^\d]', timestamp.replace('+00:00', ''))))