-
Notifications
You must be signed in to change notification settings - Fork 238
Expand file tree
/
Copy pathbackend.py
More file actions
51 lines (44 loc) · 1.2 KB
/
backend.py
File metadata and controls
51 lines (44 loc) · 1.2 KB
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
import itertools
from typing import (
Generator,
Iterator,
Dict,
Sequence,
Optional,
TYPE_CHECKING,
)
from ..base.backend import BaseBackendMixin
from .... import Document
if TYPE_CHECKING:
from ....types import (
DocumentArraySourceType,
)
class BackendMixin(BaseBackendMixin):
"""Provide necessary functions to enable this storage backend."""
def _init_storage(
self,
_docs: Optional['DocumentArraySourceType'] = None,
copy: bool = False,
*args,
**kwargs
):
super()._init_storage(_docs, copy=copy, *args, **kwargs)
from ... import DocumentArray
self._data = {}
if _docs is None:
return
elif isinstance(
_docs,
(DocumentArray, Sequence, Generator, Iterator, itertools.chain),
):
if copy:
for doc in _docs:
self.append(Document(doc, copy=True))
else:
self.extend(_docs)
else:
if isinstance(_docs, Document):
if copy:
self.append(Document(_docs, copy=True))
else:
self.append(_docs)