Skip to content

Commit

Permalink
update typing for Tuple
Browse files Browse the repository at this point in the history
fix issue flyteorg#1710
flyteorg/flyte#1710
change typing hints from ( , ) to Tuple[ , ]

Signed-off-by: Qiwen Yu <[email protected]>
  • Loading branch information
Qiwen-Yu committed Oct 29, 2021
1 parent 2a8fd0a commit 5fdbf08
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
7 changes: 4 additions & 3 deletions cookbook/core/containerization/use_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
# %%
import os
import flytekit
from typing import Tuple

# %%
# Flytekit exposes a type/class called Secrets. It can be imported as follows.
Expand Down Expand Up @@ -120,7 +121,7 @@ def secret_task() -> str:
# The Secret structure allows passing two fields, matching the key and the group, as previously described:
@task(
secret_requests=[Secret(key=USERNAME_SECRET, group=SECRET_GROUP), Secret(key=PASSWORD_SECRET, group=SECRET_GROUP)])
def user_info_task() -> (str, str):
def user_info_task() -> Tuple[str, str]:
secret_username = flytekit.current_context().secrets.get(SECRET_GROUP, USERNAME_SECRET)
secret_pwd = flytekit.current_context().secrets.get(SECRET_GROUP, PASSWORD_SECRET)
# Please do not print the secret value, this is just a demonstration.
Expand All @@ -135,7 +136,7 @@ def user_info_task() -> (str, str):
# In these scenarios you can specify the mount_requirement. In the following example we force the mounting to be
# an Env variable
@task(secret_requests=[Secret(group=SECRET_GROUP, key=SECRET_NAME, mount_requirement=Secret.MountType.ENV_VAR)])
def secret_file_task() -> (str, str):
def secret_file_task() -> Tuple[str, str]:
# SM here is a handle to the secrets manager
sm = flytekit.current_context().secrets
f = sm.get_secrets_file(SECRET_GROUP, SECRET_NAME)
Expand All @@ -147,7 +148,7 @@ def secret_file_task() -> (str, str):
# %%
# These tasks can be used in your workflow as usual
@workflow
def my_secret_workflow() -> (str, str, str, str, str):
def my_secret_workflow() -> Tuple[str, str, str, str, str]:
x = secret_task()
y, z = user_info_task()
f, s = secret_file_task()
Expand Down
8 changes: 4 additions & 4 deletions cookbook/core/control_flow/subworkflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"""

import typing

from typing import Tuple
from flytekit import task, workflow


Expand All @@ -54,7 +54,7 @@ def t1(a: int) -> op:
# This will be the subworkflow of our examples, but note that this is a workflow like any other. It can be run just
# like any other workflow. Note here that the workflow has been declared with a default.
@workflow
def my_subwf(a: int = 42) -> (str, str):
def my_subwf(a: int = 42) -> Tuple[str, str]:
x, y = t1(a=a)
u, v = t1(a=x)
return y, v
Expand All @@ -74,7 +74,7 @@ def my_subwf(a: int = 42) -> (str, str):
#
# Also note the use of with_overrides to provide a new name to the graph-node for better rendering or readability
@workflow
def parent_wf(a: int) -> (int, str, str):
def parent_wf(a: int) -> Tuple[int, str, str]:
x, y = t1(a=a).with_overrides(node_name="node-t1-parent")
u, v = my_subwf(a=x)
return x, u, v
Expand All @@ -93,7 +93,7 @@ def parent_wf(a: int) -> (int, str, str):
# can be simply composed from other workflows, even if the other workflows are standalone entities. Each of the
# workflows in this module can exist independently and executed independently
@workflow
def nested_parent_wf(a: int) -> (int, str, str, str):
def nested_parent_wf(a: int) -> Tuple[int, str, str, str]:
x, y = my_subwf(a=a)
m, n, o = parent_wf(a=a)
return m, n, o, y
Expand Down
3 changes: 2 additions & 1 deletion cookbook/core/flyte_basics/task_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ def square(n: int) -> int:
# If in a subsequent code update, we update the signature of the task to return the original number along with the result, it'll automatically invalidate the cache (even though the cache version remains the same).
#
# .. code-block:: python
# from typing import Tuple
#
# @task(cache=True, cache_version="1.0")
# def square(n: int) -> (int, int):
# def square(n: int) -> Tuple[int, int]:
# ...

# %%
Expand Down
4 changes: 2 additions & 2 deletions cookbook/core/type_system/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
valid default.
"""
from flytekit import task, workflow
import typing
from typing import Tuple
from enum import Enum


Expand Down Expand Up @@ -50,7 +50,7 @@ def string_to_enum(c: str) -> Color:


@workflow
def enum_wf(c: Color = Color.RED) -> (Color, str):
def enum_wf(c: Color = Color.RED) -> Tuple[Color, str]:
v = enum_stringify(c=c)
return string_to_enum(c=v), v

Expand Down

0 comments on commit 5fdbf08

Please sign in to comment.