-
Notifications
You must be signed in to change notification settings - Fork 237
Expand file tree
/
Copy pathattribute.py
More file actions
29 lines (20 loc) · 847 Bytes
/
attribute.py
File metadata and controls
29 lines (20 loc) · 847 Bytes
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
from typing import List, Union, Any
from docarray.helper import dunder_get
class GetAttributesMixin:
"""Provide helper functions for :class:`Document` to allow advanced set and get attributes"""
def _get_attributes(self, *fields: str) -> Union[Any, List[Any]]:
"""Bulk fetch Document fields and return a list of the values of these fields
:param fields: the variable length values to extract from the document
:return: a list with the attributes of this document ordered as the args
"""
ret = []
for k in fields:
if '__' in k:
value = dunder_get(self, k)
else:
value = getattr(self, k)
ret.append(value)
# unboxing if args is single
if len(fields) == 1:
ret = ret[0]
return ret