pycord icon indicating copy to clipboard operation
pycord copied to clipboard

feat: Replaced useless `cached_property` with `property` and moved to `functools.cached_property`

Open RiccardoVaccari opened this issue 8 months ago • 6 comments

Summary

Fixes #2660 Replaced all cached_property with property or functools.cached_property based on the solution mentioned in the issue.

Information

  • [x] This PR fixes an issue.
  • [ ] This PR adds something new (e.g. new method or parameters).
  • [x] This PR is a breaking change (e.g. methods or parameters removed/renamed).
  • [ ] This PR is not a code change (e.g. documentation, README, typehinting, examples, ...).

Checklist

  • [x] I have searched the open pull requests for duplicates.
  • [ ] If code changes were made then they have been tested.
    • [ ] I have updated the documentation to reflect the changes.
  • [ ] If type: ignore comments were used, a comment is also left explaining why.
  • [ ] I have updated the changelog to include these changes.

RiccardoVaccari avatar Apr 27 '25 07:04 RiccardoVaccari

See https://github.com/Pycord-Development/pycord/pull/2636#issuecomment-2506449499 and https://github.com/Pycord-Development/pycord/pull/2636#issuecomment-2514792776

DA-344 avatar Apr 27 '25 08:04 DA-344

Do you think is better to replace the two cached_property remained with property or evaluating the use of utils.cached_slots_property?

RiccardoVaccari avatar Apr 27 '25 09:04 RiccardoVaccari

the two cached_property remained

~~@RiccardoVaccari So there are two remaining cached_propertys ? Would you mind sending a reference to them ? This should not be merged before they are replaced then.~~

nvm, I missunderstood, you meant it already uses functools.cached_property. Well in that case we should keep that, as the point of the original issue is to use as much built in code and not custom code as possible, also see as DA344 said.

Paillat-dev avatar Apr 27 '25 11:04 Paillat-dev

Do you think is better to replace the two cached_property remained with property or evaluating the use of utils.cached_slots_property?

Keeping them as is it’s fine, it saves a function call because the data where cached_property is used is static, ie created_at, it’s bound to the id, and IDs cannot change, so calculating it everything it gets the property attr is not worth it, and it’s also not that necessary to be stored on a class attribute.

DA-344 avatar Apr 27 '25 11:04 DA-344

Do I need to fix this based on suggestions?

RiccardoVaccari avatar May 20 '25 10:05 RiccardoVaccari

Yeah

Paillat-dev avatar May 20 '25 11:05 Paillat-dev

Merge conflicts

Lulalaby avatar Aug 02 '25 03:08 Lulalaby

@Lulalaby should be good

Paillat-dev avatar Aug 05 '25 19:08 Paillat-dev