Skip to content

Commit 7e457cd

Browse files
committed
fix: judge based on Python version
1 parent 8f29d92 commit 7e457cd

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

docarray/array/any_array.py

Lines changed: 3 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 (
@@ -51,11 +52,11 @@ def __repr__(self):
5152
@classmethod
5253
def __class_getitem__(cls, item: Union[Type[BaseDocWithoutId], TypeVar, str]):
5354
if not isinstance(item, type):
54-
try:
55+
if sys.version_info < (3, 12):
5556
return Generic.__class_getitem__.__func__(cls, item) # type: ignore
5657
# this do nothing that checking that item is valid type var or str
5758
# Keep the approach in #1147 to be compatible with lower versions of Python.
58-
except AttributeError:
59+
else:
5960
from types import GenericAlias
6061
return GenericAlias(cls, item) # type: ignore
6162
if not safe_issubclass(item, BaseDocWithoutId):

0 commit comments

Comments
 (0)