Skip to content

Commit

Permalink
doc: LazyProps doctest attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
thorwhalen committed Apr 16, 2024
1 parent 61a5633 commit a2a467f
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion meshed/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a2a467f

Please sign in to comment.