Implement decorator to create read-only lazy attributes #856
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
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)
The text was updated successfully, but these errors were encountered: