-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Kenny Workman <[email protected]>
- Loading branch information
1 parent
ffb2e6c
commit 7302a05
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import json as _json | ||
from typing import Any, Dict | ||
|
||
from flyteidl.core import types_pb2 as _types_pb2 | ||
from google.protobuf import json_format as _json_format | ||
from google.protobuf import struct_pb2 as _struct | ||
|
||
|
||
class TypeAnnotation: | ||
"""Python class representation of the flyteidl TypeAnnotation message.""" | ||
|
||
def __init__(self, annotations: Dict[str, Any]): | ||
self._annotations = annotations | ||
|
||
@property | ||
def annotations(self) -> Dict[str, Any]: | ||
""" | ||
:rtype: dict[str, Any] | ||
""" | ||
return self._annotations | ||
|
||
def to_flyte_idl(self) -> _types_pb2.TypeAnnotation: | ||
""" | ||
:rtype: flyteidl.core.types_pb2.TypeAnnotation | ||
""" | ||
|
||
if self._annotations is not None: | ||
annotations = _json_format.Parse(_json.dumps(self.annotations), _struct.Struct()) | ||
else: | ||
annotations = None | ||
|
||
t = _types_pb2.TypeAnnotation( | ||
annotations=annotations, | ||
) | ||
|
||
return t | ||
|
||
@classmethod | ||
def from_flyte_idl(cls, proto): | ||
""" | ||
:param flyteidl.core.types_pb2.TypeAnnotation proto: | ||
:rtype: TypeAnnotation | ||
""" | ||
|
||
return cls(annotations=proto.annotations) |