We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 309aa8a commit f30f425Copy full SHA for f30f425
src/labthings_fastapi/base_descriptor.py
@@ -348,6 +348,13 @@ def instance_get(self, obj: Thing) -> Value:
348
)
349
350
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.
358
_class_attribute_docstring_cache: WeakKeyDictionary[type, Mapping[str, str]] = (
359
WeakKeyDictionary()
360
0 commit comments