41
41
rich .traceback .install ()
42
42
43
43
44
- def lazy_property (func : Callable ) -> property :
45
- """
46
- A decorator to make it such that a property is lazily evaluated.
47
-
48
- When the property is first accessed, the object will not yet have a
49
- corresponding attribute, so the value will be computed by executing
50
- :arg:`func`. Any time the property is accessed thereafter, the
51
- value will just be retrieved from the object's corresponding
52
- attribute.
53
-
54
- Args:
55
- func: The function used to compute the value of the property.
56
-
57
- Returns:
58
- The lazy property decorator.
59
- """
60
- attr_name = f"_lazy_{ func .__name__ } "
61
-
62
- @property # type: ignore[misc]
63
- def _lazy_property (self ):
64
- if not hasattr (self , attr_name ):
65
- setattr (self , attr_name , func (self ))
66
- return getattr (self , attr_name )
67
-
68
- return _lazy_property # type: ignore[return-value]
69
-
70
-
71
44
class StageDuration (NamedTuple ):
72
45
"""
73
46
The duration of a stage.
@@ -250,7 +223,7 @@ def _validate_stage_name(stage_name: str) -> None:
250
223
# Parse the command line arguments.
251
224
#
252
225
253
- @lazy_property
226
+ @functools . cached_property
254
227
def parser (self ) -> ArgumentParser :
255
228
"""
256
229
The base argument parser.
@@ -261,7 +234,7 @@ def parser(self) -> ArgumentParser:
261
234
262
235
.. code-block:: python
263
236
264
- @lazy_property
237
+ @functools.cached_property
265
238
def parser(self) -> ArgumentParser:
266
239
ap = super().parser
267
240
ap.description = '''INSERT DESCRIPTION HERE'''
0 commit comments