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

Implement decorator to create read-only lazy attributes #856

Open
daniel-zullo-frequenz opened this issue Jan 30, 2024 · 0 comments
Open
Labels
part:data-pipeline Affects the data pipeline priority:low This should be addressed only if there is nothing else on the table type:enhancement New feature or enhancement visitble to users
Milestone

Comments

@daniel-zullo-frequenz
Copy link
Contributor

daniel-zullo-frequenz commented Jan 30, 2024

What's needed?

Replace the pattern in _data_pipeline to create objects only once and that lives forever by creating a decorator (or selecting an existent one) to lazily create attributes and cache them for the lifetime of the _data_pipeline.

Proposed solution

Assess the different suggestions in these comments

We tried @cached_property and @lazy, but @cached_property is really complex and uses a lock (although it is removed in Python 3.12) and both allow writing to the property, and we need them to be read-only.

Use cases

Simplify code and improve code readability when there are many lazy attributes like in _data_pipeline

Alternatives and workarounds

Write ad-hoc code to do the lazy initialization.

Additional context

Originally posted in #799 (comment)

@daniel-zullo-frequenz daniel-zullo-frequenz added part:❓ We need to figure out which part is affected priority:❓ We need to figure out how soon this should be addressed type:enhancement New feature or enhancement visitble to users labels Jan 30, 2024
@daniel-zullo-frequenz daniel-zullo-frequenz added priority:low This should be addressed only if there is nothing else on the table part:data-pipeline Affects the data pipeline and removed priority:❓ We need to figure out how soon this should be addressed part:❓ We need to figure out which part is affected labels Jan 30, 2024
@llucax llucax changed the title Implement decorator to create lazy attributes Implement decorator to create read-only lazy attributes Feb 1, 2024
@llucax llucax added this to the v1.0.0-rc8 milestone Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
part:data-pipeline Affects the data pipeline priority:low This should be addressed only if there is nothing else on the table type:enhancement New feature or enhancement visitble to users
Projects
Status: To do
Development

No branches or pull requests

2 participants