Skip to content

Commit e2434fc

Browse files
author
Joan Martinez
committed
fix: try to make generic
1 parent 949f185 commit e2434fc

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

docarray/array/any_array.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
Union,
1717
cast,
1818
overload,
19-
Tuple,
2019
)
2120

2221
import numpy as np
@@ -103,17 +102,18 @@ def _setter(self, value):
103102

104103
# # The global scope and qualname need to refer to this class a unique name.
105104
# # Otherwise, creating another _DocArrayTyped will overwrite this one.
106-
change_cls_name(
107-
_DocArrayTyped, f'{cls.__name__}', globals()
108-
)
109-
110-
if sys.version_info < (3, 12):
111-
cls.__typed_da__[cls][item] = Generic.__class_getitem__.__func__(_DocArrayTyped, item) # type: ignore
112-
# this do nothing that checking that item is valid type var or str
113-
# Keep the approach in #1147 to be compatible with lower versions of Python.
105+
if not is_pydantic_v2:
106+
change_cls_name(_DocArrayTyped, f'{cls.__name__}[{item}]', globals())
107+
cls.__typed_da__[cls][item] = _DocArrayTyped
114108
else:
115-
cls.__typed_da__[cls][item] = GenericAlias(_DocArrayTyped, item) # type: ignore
116-
109+
if sys.version_info < (3, 12):
110+
cls.__typed_da__[cls][item] = Generic.__class_getitem__.__func__(
111+
_DocArrayTyped, item
112+
) # type: ignore
113+
# this do nothing that checking that item is valid type var or str
114+
# Keep the approach in #1147 to be compatible with lower versions of Python.
115+
else:
116+
cls.__typed_da__[cls][item] = GenericAlias(_DocArrayTyped, item) # type: ignore
117117
return cls.__typed_da__[cls][item]
118118

119119
@overload

0 commit comments

Comments
 (0)