Skip to content

Commit 35ce4f2

Browse files
committed
chore: clarify comments and error messages for generic annotations
1 parent 0a13a58 commit 35ce4f2

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

python/cocoindex/tests/test_typing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,5 +539,8 @@ def test_invalid_list_kind() -> None:
539539

540540
def test_unsupported_type() -> None:
541541
typ = set
542-
with pytest.raises(ValueError, match="type unsupported yet: <class 'set'>"):
542+
with pytest.raises(
543+
ValueError,
544+
match="Unsupported as a specific type annotation for CocoIndex data type.*: <class 'set'>",
545+
):
543546
analyze_type_info(typ)

python/cocoindex/typing.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class AnalyzedTypeInfo:
169169
def analyze_type_info(t: Any) -> AnalyzedTypeInfo:
170170
"""
171171
Analyze a Python type annotation and extract CocoIndex-specific type information.
172-
Only concrete CocoIndex type annotations are supported. Raises ValueError for Any, empty, or untyped dict types.
172+
Type annotations for specific CocoIndex types are expected. Raises ValueError for Any, empty, or untyped dict types.
173173
"""
174174
if isinstance(t, tuple) and len(t) == 2:
175175
kt, vt = t
@@ -240,11 +240,12 @@ def analyze_type_info(t: Any) -> AnalyzedTypeInfo:
240240
_ = DtypeRegistry.validate_dtype_and_get_kind(elem_type)
241241
vector_info = VectorInfo(dim=None) if vector_info is None else vector_info
242242

243-
elif base_type is collections.abc.Mapping or base_type is dict:
243+
elif base_type is collections.abc.Mapping or base_type is dict or t is dict:
244244
args = typing.get_args(t)
245245
if len(args) == 0: # Handle untyped dict
246246
raise ValueError(
247-
"Untyped dict is not supported; please provide a concrete type, e.g., dict[str, Any]."
247+
"Untyped dict is not accepted as a specific type annotation; please provide a concrete type, "
248+
"e.g. a dataclass or namedtuple for Struct types, a dict[str, T] for KTable types."
248249
)
249250
else:
250251
elem_type = (args[0], args[1])
@@ -288,12 +289,10 @@ def analyze_type_info(t: Any) -> AnalyzedTypeInfo:
288289
kind = "OffsetDateTime"
289290
elif t is datetime.timedelta:
290291
kind = "TimeDelta"
291-
elif t is dict:
292+
else:
292293
raise ValueError(
293-
"Untyped dict is not supported; please provide a concrete type, e.g., dict[str, Any]."
294+
f"Unsupported as a specific type annotation for CocoIndex data type (https://cocoindex.io/docs/core/data_types): {t}"
294295
)
295-
else:
296-
raise ValueError(f"type unsupported yet: {t}")
297296

298297
return AnalyzedTypeInfo(
299298
kind=kind,

0 commit comments

Comments
 (0)