mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-19 15:36:02 +00:00
Add classproperty helper utility
This is apparently a 3.9+ only addition
This commit is contained in:
parent
b0ec22065e
commit
cd7357b93a
@ -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]:
|
||||
|
Loading…
x
Reference in New Issue
Block a user