Skip to content

Commit c6b24e7

Browse files
committed
Add comments/docstrings about cacheing in get_class_attribute_docstrings
1 parent c92500f commit c6b24e7

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/labthings_fastapi/base_descriptor.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,15 @@ class Example:
295295
just paste the example above into a Python interpreter). In that case,
296296
an empty dictionary is returned.
297297
298+
The same limitation means dynamically defined classes will result in
299+
an empty dictionary.
300+
301+
.. note::
302+
303+
This function uses a cache, so subsequent calls on the same class will
304+
return a cached value. As dynamic classes are not supported, this is
305+
not expected to be a problem.
306+
298307
:param cls: The class to inspect
299308
:return: A mapping of attribute names to docstrings. Note that this will be
300309
wrapped in a `types.MappingProxyType` to prevent accidental modification.

tests/test_base_descriptor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ def test_docstrings_are_cached():
4545
"""Check that the docstrings aren't being regenerated every time."""
4646
docs1 = get_class_attribute_docstrings(Example)
4747
docs2 = get_class_attribute_docstrings(Example)
48+
# The dictionary of attribute docstrings is cached, keyed on the
49+
# class. The test below checks the same object is returned, not
50+
# just one with the same values in it - this implies the cache
51+
# is working.
4852
assert docs1 is docs2
4953

5054

0 commit comments

Comments
 (0)