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 2ab4f9d

Browse filesBrowse files
author
Joan Fontanals Martinez
committed
fix: fix double subscriptable error
Signed-off-by: Joan Fontanals Martinez <joan.martinez@jina.ai>
1 parent 2f3b85e commit 2ab4f9d
Copy full SHA for 2ab4f9d

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

+21
-3
lines changed

‎docarray/array/doc_list/doc_list.py

Copy file name to clipboardExpand all lines: docarray/array/doc_list/doc_list.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ def __getitem__(self, item):
334334

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

338340
if isinstance(item, type) and safe_issubclass(item, BaseDoc):
339341
return AnyDocArray.__class_getitem__.__func__(cls, item) # type: ignore

‎tests/units/array/test_array.py

Copy file name to clipboardExpand all lines: tests/units/array/test_array.py
+19-3Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ class Image(BaseDoc):
467467

468468

469469
def test_validate_list_dict():
470-
471470
images = [
472471
dict(url=f'http://url.com/foo_{i}.png', tensor=NdArray(i)) for i in [2, 0, 1]
473472
]
@@ -493,7 +492,24 @@ def test_parameterize_list():
493492
from docarray import DocList, BaseDoc
494493

495494
with pytest.raises(TypeError) as excinfo:
496-
doc = DocList[BaseDoc()]
497-
assert doc is None
495+
da = DocList[BaseDoc()]
496+
assert da is None
498497

499498
assert str(excinfo.value) == 'Expecting a type, got object instead'
499+
500+
501+
def test_not_double_subcriptable():
502+
from docarray import DocList, DocVec
503+
from docarray.documents import TextDoc
504+
505+
with pytest.raises(TypeError) as excinfo:
506+
da = DocList[TextDoc][TextDoc]
507+
assert da is None
508+
509+
assert 'not subscriptable' in str(excinfo.value)
510+
511+
with pytest.raises(TypeError) as excinfo:
512+
da = DocVec[TextDoc][TextDoc]
513+
assert da is None
514+
515+
assert 'not subscriptable' in str(excinfo.value)

0 commit comments

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