-
-
Notifications
You must be signed in to change notification settings - Fork 477
Description
Summary
cached_property
is often unnecessary and can be replaced with property
or functools.cached_property
(if some criteria are met)
What is the feature request for?
The core library
The Problem
The goal of cached_property
is to prevent from recalculating compute (intensive) code when the result is not expected to change. However, it is used all over the place in the library without any scope. It does not cache any compute intensive code, and at best, makes it arguably less memory efficient. Also, it causes typing and documentation rendering issues.
The Ideal Solution
The solution would be to do the following for every usage of utils.cached_property
:
- If no compute intensive code is present (90% of the cases), replace it with
property
- If compute intensive code is present, and the function does not provide
__dict__
in__slots__
(see here why, altough it should never be the case as pycord usescached_slot_property
, but is good to mention), repalce it withfunctools.cached_property
.
With the goal of utlimately entirely removing cached_property
.
The Current Solution
n/a
Additional Context
- ApplicationContext attributes have wrong type annotations #2635
- fix: use
property
instead ofNewType(...)
to fix type annotations for ApplicationContext attributes #2636 - https://discord.com/channels/881207955029110855/881735314987708456/1304609838101172286
- https://docs.python.org/3/library/functools.html#functools.cached_property
pycord/discord/commands/context.py
Line 223 in 61cc544
@cached_property pycord/discord/commands/context.py
Line 167 in 61cc544
@cached_property - And many more such examples