Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix: fix double subscriptable error
Signed-off-by: Joan Fontanals Martinez <[email protected]>
  • Loading branch information
Joan Fontanals Martinez committed Sep 20, 2023
commit fc41eb01eaaab0cc16dd99451d1e01f51d16a9f1
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 @@ -334,6 +334,8 @@ def __getitem__(self, item):

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

if isinstance(item, type) and safe_issubclass(item, BaseDoc):
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)