Skip to content

Replace cached_property with property or functools_property #2660

@Paillat-dev

Description

@Paillat-dev

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions