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 7209b78

Browse filesBrowse files
author
Joan Fontanals
authored
fix: fix double subscriptable error (#1800)
Signed-off-by: Joan Fontanals Martinez <joan.martinez@jina.ai> Signed-off-by: Joan Fontanals <joan.martinez@jina.ai>
1 parent dce3907 commit 7209b78
Copy full SHA for 7209b78

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

+15
-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
@@ -335,6 +335,8 @@ def __getitem__(self, item):
335335

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

339341
if isinstance(item, type) and safe_issubclass(item, BaseDocWithoutId):
340342
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
+13-3Lines changed: 13 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,18 @@ 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
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)

0 commit comments

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