Skip to content

Commit

Permalink
feat: proto model
Browse files Browse the repository at this point in the history
Signed-off-by: Kenny Workman <[email protected]>
  • Loading branch information
kennyworkman committed Dec 1, 2021
1 parent ffb2e6c commit 7302a05
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions flytekit/models/annotation.py
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)

0 comments on commit 7302a05

Please sign in to comment.