Skip to content

Commit

Permalink
fix: try to make generic
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanFM committed Mar 14, 2024
1 parent 949f185 commit e2434fc
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions docarray/array/any_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
Union,
cast,
overload,
Tuple,
)

import numpy as np
Expand Down Expand Up @@ -103,17 +102,18 @@ def _setter(self, value):

# # The global scope and qualname need to refer to this class a unique name.
# # Otherwise, creating another _DocArrayTyped will overwrite this one.
change_cls_name(
_DocArrayTyped, f'{cls.__name__}', globals()
)

if sys.version_info < (3, 12):
cls.__typed_da__[cls][item] = Generic.__class_getitem__.__func__(_DocArrayTyped, item) # type: ignore
# this do nothing that checking that item is valid type var or str
# Keep the approach in #1147 to be compatible with lower versions of Python.
if not is_pydantic_v2:
change_cls_name(_DocArrayTyped, f'{cls.__name__}[{item}]', globals())
cls.__typed_da__[cls][item] = _DocArrayTyped
else:
cls.__typed_da__[cls][item] = GenericAlias(_DocArrayTyped, item) # type: ignore

if sys.version_info < (3, 12):
cls.__typed_da__[cls][item] = Generic.__class_getitem__.__func__(
_DocArrayTyped, item
) # type: ignore
# this do nothing that checking that item is valid type var or str
# Keep the approach in #1147 to be compatible with lower versions of Python.
else:
cls.__typed_da__[cls][item] = GenericAlias(_DocArrayTyped, item) # type: ignore

Check warning on line 116 in docarray/array/any_array.py

View check run for this annotation

Codecov / codecov/patch

docarray/array/any_array.py#L116

Added line #L116 was not covered by tests
return cls.__typed_da__[cls][item]

@overload
Expand Down

0 comments on commit e2434fc

Please sign in to comment.