From cd7357b93ad8234e7e9a97dbb666928f426a7587 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sun, 2 May 2021 08:05:52 -0400 Subject: [PATCH] Add classproperty helper utility This is apparently a 3.9+ only addition --- discord/utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/discord/utils.py b/discord/utils.py index bd29caabc..072293124 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -155,6 +155,15 @@ class CachedSlotProperty(Generic[T, T_co]): setattr(instance, self.name, value) return value +class classproperty(Generic[T_co]): + def __init__(self, fget: Callable[[Any], T_co]) -> None: + self.fget = fget + + def __get__(self, instance: Optional[Any], owner: Type[Any]) -> T_co: + return self.fget(owner) + + def __set__(self, instance, value) -> None: + raise AttributeError('cannot set attribute') def cached_slot_property(name: str) -> Callable[[Callable[[T], T_co]], CachedSlotProperty[T, T_co]]: def decorator(func: Callable[[T], T_co]) -> CachedSlotProperty[T, T_co]: