diff --git a/docarray/document/data.py b/docarray/document/data.py index b052b6eea86..604f057b516 100644 --- a/docarray/document/data.py +++ b/docarray/document/data.py @@ -2,7 +2,7 @@ import os from collections import defaultdict from dataclasses import dataclass, field, fields -from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union +from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union, Any from docarray.math.ndarray import check_arraylike_equality @@ -70,7 +70,7 @@ class DocumentData: content: Optional['DocumentContentType'] = None weight: Optional[float] = None uri: Optional[str] = None - tags: Optional[Dict[str, 'StructValueType']] = None + tags: Optional[Dict[str, Any]] = None _metadata: Optional[Dict[str, 'StructValueType']] = None offset: Optional[float] = None location: Optional[List[float]] = None diff --git a/docarray/document/mixins/_property.py b/docarray/document/mixins/_property.py index ea2f56e348f..bddcc8156cd 100644 --- a/docarray/document/mixins/_property.py +++ b/docarray/document/mixins/_property.py @@ -1,7 +1,7 @@ -# auto-generated from /Users/hanxiao/Documents/docarray/scripts/gen_doc_property_mixin.py -from typing import TYPE_CHECKING, Dict, List, Optional +# auto-generated from docarray/scripts/gen_doc_property_mixin.py +from typing import TYPE_CHECKING, Dict, List, Optional, Union, Any -if TYPE_CHECKING: # pragma: no cover +if TYPE_CHECKING: from docarray.score import NamedScore from docarray.array.match import MatchArray from docarray.array.chunk import ChunkArray @@ -110,12 +110,12 @@ def uri(self, value: str): self._data.uri = value @property - def tags(self) -> Optional[Dict[str, 'StructValueType']]: + def tags(self) -> Optional[Dict[str, Any]]: self._data._set_default_value_if_none('tags') return self._data.tags @tags.setter - def tags(self, value: Dict[str, 'StructValueType']): + def tags(self, value: Dict[str, Any]): self._data.tags = value @property @@ -164,21 +164,21 @@ def modality(self, value: str): self._data.modality = value @property - def evaluations(self) -> Optional[Dict[str, 'NamedScore']]: + def evaluations(self) -> Optional[Dict[str, Union['NamedScore', Dict]]]: self._data._set_default_value_if_none('evaluations') return self._data.evaluations @evaluations.setter - def evaluations(self, value: Dict[str, 'NamedScore']): + def evaluations(self, value: Dict[str, Union['NamedScore', Dict]]): self._data.evaluations = value @property - def scores(self) -> Optional[Dict[str, 'NamedScore']]: + def scores(self) -> Optional[Dict[str, Union['NamedScore', Dict]]]: self._data._set_default_value_if_none('scores') return self._data.scores @scores.setter - def scores(self, value: Dict[str, 'NamedScore']): + def scores(self, value: Dict[str, Union['NamedScore', Dict]]): self._data.scores = value @property diff --git a/scripts/gen_doc_property_mixin.py b/scripts/gen_doc_property_mixin.py index 860867ef123..226d4280e19 100644 --- a/scripts/gen_doc_property_mixin.py +++ b/scripts/gen_doc_property_mixin.py @@ -1,18 +1,21 @@ +import os import re from dataclasses import fields +from pathlib import Path + from docarray.document.data import DocumentData with open('../docarray/document/mixins/_property.py', 'w') as fp: fp.write( - f'''# auto-generated from {__file__} -from typing import TYPE_CHECKING, Dict, List, Optional + f'''# auto-generated from {os.path.relpath(__file__, start=Path(__file__).parent.parent.parent)} +from typing import TYPE_CHECKING, Dict, List, Optional, Union, Any if TYPE_CHECKING: - from ...score import NamedScore - from ...array.match import MatchArray - from ...array.chunk import ChunkArray - from ... import DocumentArray - from ...typing import ArrayType, StructValueType, DocumentContentType + from docarray.score import NamedScore + from docarray.array.match import MatchArray + from docarray.array.chunk import ChunkArray + from docarray import DocumentArray + from docarray.typing import ArrayType, StructValueType, DocumentContentType class _PropertyMixin: @@ -23,11 +26,10 @@ class _PropertyMixin: continue ftype = ( str(f.type) - .replace('typing.Dict', 'Dict') - .replace('typing.List', 'List') + .replace('typing.', '') .replace('datetime.datetime', '\'datetime\'') ) - ftype = re.sub(r'typing.Union\[(.*), NoneType]', r'Optional[\g<1>]', ftype) + ftype = re.sub(r'Union\[(.*), NoneType]', r'Optional[\g<1>]', ftype) ftype = re.sub(r'ForwardRef\((\'.*\')\)', r'\g<1>', ftype) ftype = re.sub(r'', r'\g<1>', ftype)