Skip to content

Commit fc41eb0

Browse files
author
Joan Fontanals Martinez
committed
fix: fix double subscriptable error
Signed-off-by: Joan Fontanals Martinez <[email protected]>
1 parent 2f3b85e commit fc41eb0

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

docarray/array/doc_list/doc_list.py

Lines 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

Lines 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)