Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
59 lines (50 loc) · 1.7 KB

File metadata and controls

59 lines (50 loc) · 1.7 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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 {os.path.relpath(__file__, start=Path(__file__).parent.parent.parent)}
from typing import TYPE_CHECKING, Dict, List, Optional, Union, Any
if TYPE_CHECKING:
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:
'''
)
for f in fields(DocumentData):
if f.name.startswith('_'):
continue
ftype = (
str(f.type)
.replace('typing.', '')
.replace('datetime.datetime', '\'datetime\'')
)
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)
r_ftype = ftype
if f.name == 'chunks':
r_ftype = 'Optional[\'ChunkArray\']'
elif f.name == 'matches':
r_ftype = 'Optional[\'MatchArray\']'
fp.write(
f'''
@property
def {f.name}(self) -> {r_ftype}:
self._data._set_default_value_if_none('{f.name}')
return self._data.{f.name}
'''
)
ftype = re.sub(r'Optional\[(.*)]', r'\g<1>', ftype)
fp.write(
f'''
@{f.name}.setter
def {f.name}(self, value: {ftype}):
self._data.{f.name} = value
'''
)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.