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 1f86e26

Browse filesBrowse files
authored
fix: error type hints in Python3.12 (#1147) (#1840)
Signed-off-by: 954 <510485871@qq.com>
1 parent a2421a6 commit 1f86e26
Copy full SHA for 1f86e26

File tree

1 file changed

+10
-2
lines changed
Filter options

1 file changed

+10
-2
lines changed

‎docarray/array/any_array.py

Copy file name to clipboardExpand all lines: docarray/array/any_array.py
+10-2Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
import random
23
from abc import abstractmethod
34
from typing import (
@@ -29,6 +30,9 @@
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+
3236
T = TypeVar('T', bound='AnyDocArray')
3337
T_doc = TypeVar('T_doc', bound=BaseDocWithoutId)
3438
IndexIterType = 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

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