-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathabstract_type.py
More file actions
46 lines (35 loc) · 1 KB
/
Copy pathabstract_type.py
File metadata and controls
46 lines (35 loc) · 1 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
from abc import abstractmethod
from typing import TYPE_CHECKING, Any, Optional, Type, TypeVar
from pydantic import BaseConfig
from pydantic.fields import ModelField
from docarray.base_doc.base_node import BaseNode
if TYPE_CHECKING:
from docarray.proto import NodeProto
T = TypeVar('T')
class AbstractType(BaseNode):
_proto_type_name: Optional[str] = None
@classmethod
def __get_validators__(cls):
yield cls.validate
@classmethod
@abstractmethod
def validate(
cls: Type[T],
value: Any,
field: 'ModelField',
config: 'BaseConfig',
) -> T:
...
@classmethod
@abstractmethod
def from_protobuf(cls: Type[T], pb_msg: T) -> T:
...
@abstractmethod
def _to_node_protobuf(self: T) -> 'NodeProto':
...
def _docarray_to_json_compatible(self):
"""
Convert itself into a json compatible object
:return: a representation of the tensor compatible with orjson
"""
return self