From 75335d03e72a0e3f5600a11eaa81f253414bec67 Mon Sep 17 00:00:00 2001 From: LJ Date: Thu, 20 Mar 2025 18:57:19 -0700 Subject: [PATCH] Use class docstring as description for struct types in Python SDK. --- python/cocoindex/typing.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/cocoindex/typing.py b/python/cocoindex/typing.py index ffaa3bd6..f5547d56 100644 --- a/python/cocoindex/typing.py +++ b/python/cocoindex/typing.py @@ -2,6 +2,7 @@ import collections import dataclasses import types +import inspect from typing import Annotated, NamedTuple, Any, TypeVar, TYPE_CHECKING, overload class Vector(NamedTuple): @@ -147,6 +148,8 @@ def _encode_type(type_info: AnalyzedTypeInfo) -> dict[str, Any]: if type_info.dataclass_type is None: raise ValueError("Struct type must have a dataclass type") encoded_type['fields'] = _encode_fields_schema(type_info.dataclass_type) + if doc := inspect.getdoc(type_info.dataclass_type): + encoded_type['description'] = doc elif type_info.kind == 'Vector': if type_info.vector_info is None: