Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docarray/array/doc_list/doc_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ def __getitem__(self, item):

@classmethod
def __class_getitem__(cls, item: Union[Type[BaseDocWithoutId], TypeVar, str]):
if cls.doc_type != AnyDoc:
raise TypeError(f'{cls} object is not subscriptable')

if isinstance(item, type) and safe_issubclass(item, BaseDocWithoutId):
return AnyDocArray.__class_getitem__.__func__(cls, item) # type: ignore
Expand Down
16 changes: 13 additions & 3 deletions tests/units/array/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,6 @@ class Image(BaseDoc):


def test_validate_list_dict():

images = [
dict(url=f'http://url.com/foo_{i}.png', tensor=NdArray(i)) for i in [2, 0, 1]
]
Expand All @@ -493,7 +492,18 @@ def test_parameterize_list():
from docarray import DocList, BaseDoc

with pytest.raises(TypeError) as excinfo:
doc = DocList[BaseDoc()]
assert doc is None
da = DocList[BaseDoc()]
assert da is None

assert str(excinfo.value) == 'Expecting a type, got object instead'


def test_not_double_subcriptable():
from docarray import DocList
from docarray.documents import TextDoc

with pytest.raises(TypeError) as excinfo:
da = DocList[TextDoc][TextDoc]
assert da is None

assert 'not subscriptable' in str(excinfo.value)