-
Notifications
You must be signed in to change notification settings - Fork 339
TypeAnnotation #759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
eapolinario
merged 44 commits into
flyteorg:master
from
kennyworkman:kenny/type-annotation
Feb 8, 2022
Merged
TypeAnnotation #759
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
71619aa
feat: support for annotated simple + list
kennyworkman ac27cc0
feat: addition of annotation att to
kennyworkman 1417294
feat: core obj
kennyworkman e089b17
feat: proto model
kennyworkman a41e545
feat: testing suite
kennyworkman eb41882
fix: more stable typing introspection
kennyworkman 83777e8
fix: strip legacy
kennyworkman 8ec23a7
fix: explicitly allow only one annotation
kennyworkman 10ba63c
feat: direct type transformer tests
kennyworkman a3cc48f
fix: there and back test
kennyworkman 1582dfb
fix: typing_extensions for get_origin
kennyworkman 8c5ee52
fix: more semantic list generic unwrap
kennyworkman a6378d4
fix: tmp requirements file with custom idl
kennyworkman f144ffa
fix: nits
kennyworkman 7508cc9
feat: semantic error for unsupported complex literals
kennyworkman 8bc240b
fix: but
kennyworkman e7f6bb5
feat: more tests ;)
kennyworkman 8c2b2d8
fix: imports
kennyworkman 60089d3
fix: complex annotations
kennyworkman fb302ad
fix: temp requirements files for unit tests
kennyworkman df8356a
fix: lint bug
kennyworkman 084e46e
fix: tmp setup.py
kennyworkman c245cbf
fix: use typing_extensions
kennyworkman 43eaa8c
fix: typing_extensions for annotated
kennyworkman 1a5840f
fix: typing_ext
kennyworkman c0c3073
fix: plugin tmp requirements
kennyworkman a6a6cb4
fix: bump requirements
kennyworkman 9df04ea
fix: doc requirements
kennyworkman 0ed30b8
fix: whitespace
kennyworkman 5fc72d4
fix: bump flytekit
kennyworkman 9f62e9c
fix: numpy version
kennyworkman 4dbbac9
fix: lint
kennyworkman 75c91d9
fix: pandas version
kennyworkman 183f110
fix: bump requirements
kennyworkman d3f4830
fix: test import
kennyworkman 854b96f
fix: flake8 lint
kennyworkman 5173271
fix: merge
kennyworkman 2ec2d94
fix: merge
kennyworkman 956f8e6
fix: requirements
kennyworkman 19d5642
fix: requirements
kennyworkman 755f31f
fix: lint
kennyworkman 0c232e8
Merge remote-tracking branch 'real/master' into kenny/type-annotation
kennyworkman 4d64acd
fix: papermill req
kennyworkman 88bc4d0
fix: req
kennyworkman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| *.pyt | ||
| *.pytc | ||
| *.egg-info | ||
| .*.swp | ||
| .*.sw* | ||
| .DS_Store | ||
| venv/ | ||
| .venv/ | ||
|
|
||
This file contains hidden or 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
This file contains hidden or 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,30 @@ | ||
| from typing import Any, Dict | ||
|
|
||
|
|
||
| class FlyteAnnotation: | ||
| """A core object to add arbitrary annotations to flyte types. | ||
|
|
||
| This metadata is ingested as a python dictionary and will be serialized | ||
| into fields on the flyteidl type literals. This data is not accessible at | ||
| runtime but rather can be retrieved from flyteadmin for custom presentation | ||
| of typed parameters. | ||
|
|
||
| Flytekit expects to receive a maximum of one `FlyteAnnotation` object | ||
| within each typehint. | ||
|
|
||
| For a task definition: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| @task | ||
| def x(a: typing.Annotated[int, FlyteAnnotation({"foo": {"bar": 1}})]): | ||
|
kennyworkman marked this conversation as resolved.
|
||
| return | ||
|
|
||
| """ | ||
|
|
||
| def __init__(self, data: Dict[str, Any]): | ||
| self._data = data | ||
|
|
||
| @property | ||
| def data(self): | ||
|
kennyworkman marked this conversation as resolved.
|
||
| return self._data | ||
This file contains hidden or 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
This file contains hidden or 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,43 @@ | ||
| 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: | ||
|
kennyworkman marked this conversation as resolved.
|
||
| """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 | ||
|
|
||
| return _types_pb2.TypeAnnotation( | ||
| annotations=annotations, | ||
| ) | ||
|
|
||
| @classmethod | ||
| def from_flyte_idl(cls, proto): | ||
| """ | ||
| :param flyteidl.core.types_pb2.TypeAnnotation proto: | ||
| :rtype: TypeAnnotation | ||
| """ | ||
|
|
||
| return cls(annotations=_json_format.MessageToDict(proto.annotations)) | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.