Skip to content

Commit 158ff79

Browse files
authored
Use class docstring as description for struct types in Python SDK. (#187)
1 parent cff0589 commit 158ff79

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

python/cocoindex/typing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import collections
33
import dataclasses
44
import types
5+
import inspect
56
from typing import Annotated, NamedTuple, Any, TypeVar, TYPE_CHECKING, overload
67

78
class Vector(NamedTuple):
@@ -147,6 +148,8 @@ def _encode_type(type_info: AnalyzedTypeInfo) -> dict[str, Any]:
147148
if type_info.dataclass_type is None:
148149
raise ValueError("Struct type must have a dataclass type")
149150
encoded_type['fields'] = _encode_fields_schema(type_info.dataclass_type)
151+
if doc := inspect.getdoc(type_info.dataclass_type):
152+
encoded_type['description'] = doc
150153

151154
elif type_info.kind == 'Vector':
152155
if type_info.vector_info is None:

0 commit comments

Comments
 (0)