Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docarray/document/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions docarray/document/mixins/_property.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 12 additions & 10 deletions scripts/gen_doc_property_mixin.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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'<class \'(.*)\'>', r'\g<1>', ftype)

Expand Down