Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2f3b85e

Browse filesBrowse files
authored
fix: raise exception when type of DocList is object (#1794)
Signed-off-by: punndcoder28 <puneethk.2899@gmail.com>
1 parent 8f32866 commit 2f3b85e
Copy full SHA for 2f3b85e

File tree

Expand file treeCollapse file tree

2 files changed

+20
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+20
-3
lines changed

‎docarray/array/doc_list/doc_list.py

Copy file name to clipboardExpand all lines: docarray/array/doc_list/doc_list.py
+10-3Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from pydantic import parse_obj_as
1818
from typing_extensions import SupportsIndex
19-
from typing_inspect import is_union_type
19+
from typing_inspect import is_union_type, is_typevar
2020

2121
from docarray.array.any_array import AnyDocArray
2222
from docarray.array.doc_list.io import IOMixinDocList
@@ -337,8 +337,15 @@ 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 is_typevar(item)
343+
and not isinstance(item, str)
344+
and item is not Any
345+
):
346+
raise TypeError('Expecting a type, got object instead')
347+
348+
return super().__class_getitem__(item)
342349

343350
def __repr__(self):
344351
return AnyDocArray.__repr__(self) # type: ignore

‎tests/units/array/test_array.py

Copy file name to clipboardExpand all lines: tests/units/array/test_array.py
+10Lines 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+
assert doc is None
498+
499+
assert str(excinfo.value) == 'Expecting a type, got object instead'

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.