Skip to content

Commit 9ba1f6a

Browse files
authored
chore: relax analyze_type_info() to return unknown variant when so (#809)
1 parent 0eaa7a2 commit 9ba1f6a

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

python/cocoindex/tests/test_typing.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
AnalyzedDictType,
1414
AnalyzedListType,
1515
AnalyzedStructType,
16+
AnalyzedUnknownType,
1617
AnalyzedTypeInfo,
1718
TypeAttr,
1819
TypeKind,
@@ -422,15 +423,7 @@ def test_annotated_list_with_type_kind() -> None:
422423
assert result.variant.kind == "Struct"
423424

424425

425-
def test_unsupported_type() -> None:
426-
with pytest.raises(
427-
ValueError,
428-
match="Unsupported as a specific type annotation for CocoIndex data type.*: <class 'set'>",
429-
):
430-
analyze_type_info(set)
431-
432-
with pytest.raises(
433-
ValueError,
434-
match="Unsupported as a specific type annotation for CocoIndex data type.*: <class 'numpy.complex64'>",
435-
):
436-
Vector[np.complex64]
426+
def test_unknown_type() -> None:
427+
typ = set
428+
result = analyze_type_info(typ)
429+
assert isinstance(result.variant, AnalyzedUnknownType)

python/cocoindex/typing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,11 @@ def analyze_type_info(t: Any) -> AnalyzedTypeInfo:
313313
kind = "OffsetDateTime"
314314
elif t is datetime.timedelta:
315315
kind = "TimeDelta"
316+
317+
if kind is None:
318+
variant = AnalyzedUnknownType()
316319
else:
317-
raise ValueError(
318-
f"Unsupported as a specific type annotation for CocoIndex data type (https://cocoindex.io/docs/core/data_types): {t}"
319-
)
320-
variant = AnalyzedBasicType(kind=kind)
320+
variant = AnalyzedBasicType(kind=kind)
321321

322322
return AnalyzedTypeInfo(
323323
core_type=core_type,

0 commit comments

Comments
 (0)