1+ import sys
12import random
23from abc import abstractmethod
34from typing import (
2930 from docarray .proto import DocListProto , NodeProto
3031 from docarray .typing .tensor .abstract_tensor import AbstractTensor
3132
33+ if sys .version_info < (3 , 12 ):
34+ from types import GenericAlias
35+
3236T = TypeVar ('T' , bound = 'AnyDocArray' )
3337T_doc = TypeVar ('T_doc' , bound = BaseDocWithoutId )
3438IndexIterType = Union [slice , Iterable [int ], Iterable [bool ], None ]
@@ -51,8 +55,12 @@ def __repr__(self):
5155 @classmethod
5256 def __class_getitem__ (cls , item : Union [Type [BaseDocWithoutId ], TypeVar , str ]):
5357 if not isinstance (item , type ):
54- return Generic .__class_getitem__ .__func__ (cls , item ) # type: ignore
55- # this do nothing that checking that item is valid type var or str
58+ if sys .version_info < (3 , 12 ):
59+ return Generic .__class_getitem__ .__func__ (cls , item ) # type: ignore
60+ # this do nothing that checking that item is valid type var or str
61+ # Keep the approach in #1147 to be compatible with lower versions of Python.
62+ else :
63+ return GenericAlias (cls , item ) # type: ignore
5664 if not safe_issubclass (item , BaseDocWithoutId ):
5765 raise ValueError (
5866 f'{ cls .__name__ } [item] item should be a Document not a { item } '
0 commit comments