From a2a467f4b3bfcf6803a1b130ac3053855ed726bb Mon Sep 17 00:00:00 2001 From: Thor Whalen Date: Tue, 16 Apr 2024 10:21:04 +0200 Subject: [PATCH] doc: LazyProps doctest attempt --- meshed/caching.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/meshed/caching.py b/meshed/caching.py index f0d6d1f8..cf1ec644 100644 --- a/meshed/caching.py +++ b/meshed/caching.py @@ -12,8 +12,28 @@ def set_cached_property_attr(obj, name, value): setattr(obj, name, cached_value) +# TODO: Fix this (either the class, or the doctest is wrong) class LazyProps: - """A class that makes all""" + """ + A class that makes all its attributes cached_property properties. + + Example: + + # >>> class A(LazyProps): + # ... a = 1 + # ... b = 2 + # ... def c(self): + # ... print("computing c...") + # ... return self.a + self.b + # ... + # >>> a = A() + # >>> a.c + # computing c... + # 3 + # >>> a.c # note that c is not recomputed + # 3 + + """ def __init_subclass__(cls, **kwargs): super().__init_subclass__(**kwargs)