Skip to content

Commit f30f425

Browse files
committed
Add comment on cache
1 parent 309aa8a commit f30f425

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/labthings_fastapi/base_descriptor.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,13 @@ def instance_get(self, obj: Thing) -> Value:
348348
)
349349

350350

351+
# get_class_attribute_docstrings is a relatively expensive function that
352+
# will be called potentially quite a few times on the same class. It will
353+
# return the same result each time (because it depends only on the source
354+
# code of the class, which can't change), so it makes sense to cache it.
355+
#
356+
# We use weak keys to avoid messing up garbage collection, and cache the
357+
# mapping of attribute names to attribute docstrings.
351358
_class_attribute_docstring_cache: WeakKeyDictionary[type, Mapping[str, str]] = (
352359
WeakKeyDictionary()
353360
)

0 commit comments

Comments
 (0)