Skip to content

Commit 8621817

Browse files
committed
fix: raise exception when type of DocList is object
Signed-off-by: punndcoder28 <[email protected]>
1 parent d0b9990 commit 8621817

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

docarray/array/doc_list/doc_list.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,14 @@ def __class_getitem__(cls, item: Union[Type[BaseDoc], TypeVar, str]):
337337

338338
if isinstance(item, type) and safe_issubclass(item, BaseDoc):
339339
return AnyDocArray.__class_getitem__.__func__(cls, item) # type: ignore
340-
else:
341-
return super().__class_getitem__(item)
340+
if (
341+
isinstance(item, object)
342+
and not isinstance(item, TypeVar)
343+
and item is not Any
344+
):
345+
raise TypeError('Expecting a type, got object instead')
346+
347+
return super().__class_getitem__(item)
342348

343349
def __repr__(self):
344350
return AnyDocArray.__repr__(self) # type: ignore

tests/units/array/test_array.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,3 +487,13 @@ def test_legacy_doc():
487487
newDoc = LegacyDocument()
488488
da = DocList[LegacyDocument]([newDoc])
489489
da.summary()
490+
491+
492+
def test_parameterize_list():
493+
from docarray import DocList, BaseDoc
494+
495+
with pytest.raises(TypeError) as excinfo:
496+
doc = DocList[BaseDoc()]
497+
498+
assert str(excinfo.value) == 'Expecting a type, got object instead'
499+
assert doc is None

0 commit comments

Comments
 (0)