diff options
| author | Rapptz <[email protected]> | 2015-12-16 22:03:16 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2015-12-16 22:03:16 -0500 |
| commit | de1c74a399a5286cd707c6ebc3892e168d628ac0 (patch) | |
| tree | 5345ed742be917325f0612cdf52e5bc03d9018b6 /discord/utils.py | |
| parent | Channel.is_default_channel is now a property named is_default. (diff) | |
| download | discord.py-de1c74a399a5286cd707c6ebc3892e168d628ac0.tar.xz discord.py-de1c74a399a5286cd707c6ebc3892e168d628ac0.zip | |
Make more things into properties.
A lot of the expensive getters were transformed into cached properties
instead. A lot of things that were properties were transformed into
properties as well.
Diffstat (limited to 'discord/utils.py')
| -rw-r--r-- | discord/utils.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/discord/utils.py b/discord/utils.py index 2662b4a1..9e230262 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -31,6 +31,21 @@ from base64 import b64encode import asyncio import json + +class cached_property: + def __init__(self, function): + self.function = function + self.__doc__ = getattr(function, '__doc__') + + def __get__(self, instance, owner): + if instance is None: + return self + + value = self.function(instance) + setattr(instance, self.function.__name__, value) + + return value + def parse_time(timestamp): if timestamp: return datetime.datetime(*map(int, re_split(r'[^\d]', timestamp.replace('+00:00', '')))) |