Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Replace cache_in_self with functools.cached_property #11545

Open
ShadowJonathan opened this issue Dec 9, 2021 · 1 comment
Open

Replace cache_in_self with functools.cached_property #11545

ShadowJonathan opened this issue Dec 9, 2021 · 1 comment
Labels
T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks. z-blocked (Deprecated Label) Z-Future-Maintenance Things that can't yet be done, but will need cleaning up in a couple of months/releases

Comments

@ShadowJonathan
Copy link
Contributor

This acts a loss less magic-y and more pythonic by storing the result of its value as a direct name mapping in the instance itself.

In other words, this'll make the property function run once, and then store its value as the same name of the property, which can then be read and written to like any normal value.

To me, this looks a loss less hack-y than cache_in_self, which currently does it with underscore-prefixed values.

However, this is only available to synapse once 3.8 is the lowest supported python, see the docs

@clokep clokep added T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks. z-blocked (Deprecated Label) labels Dec 9, 2021
@squahtx squahtx added the Z-Future-Maintenance Things that can't yet be done, but will need cleaning up in a couple of months/releases label Dec 9, 2021
@callahad callahad added this to the Revisit: Next Year milestone Dec 16, 2021
@callahad
Copy link
Contributor

While we wait for Python 3.7 to age out (Summer 2023), I'd be game to see what a pull request using backports.cached-property looks like.

Rich notes that our cache_in_self does work to detect cycles which may not be happening in the stdlib functools.cached_property

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks. z-blocked (Deprecated Label) Z-Future-Maintenance Things that can't yet be done, but will need cleaning up in a couple of months/releases
Projects
None yet
Development

No branches or pull requests

4 participants