element-hq / element-hq/synapse

Replace `cache_in_self` with `functools.cached_property`

Open
#11,545 0 comments 0 reactions 0 assignees View on GitHub
T-Task z-blocked Z-Future-Maintenance
Dominant language
Python
Stars
4.6k
Forks
600
Avg merge
5d 22h
Merged PRs (30d)
51

Description

This issue has been migrated from [#11545](https://github.com/matrix-org/synapse/issues/11545).

---

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](https://docs.python.org/3/library/functools.html#functools.cached_property)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.