Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace cached_property with property or functools_property #2660

Open
Paillat-dev opened this issue Nov 28, 2024 · 0 comments
Open

Replace cached_property with property or functools_property #2660

Paillat-dev opened this issue Nov 28, 2024 · 0 comments
Labels
feature request New feature request

Comments

@Paillat-dev
Copy link
Contributor

Paillat-dev commented Nov 28, 2024

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 uses cached_slot_property, but is good to mention), repalce it with functools.cached_property.

With the goal of utlimately entirely removing cached_property.

The Current Solution

n/a

Additional Context

@Paillat-dev Paillat-dev added the feature request New feature request label Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature request
Projects
None yet
Development

No branches or pull requests

1 participant