Skip to content

Instantly share code, notes, and snippets.

@EngHabu
Created December 14, 2021 19:38
Show Gist options
  • Save EngHabu/87ef90e5559c2f31baa8c516fcb341d5 to your computer and use it in GitHub Desktop.
Save EngHabu/87ef90e5559c2f31baa8c516fcb341d5 to your computer and use it in GitHub Desktop.
# Example 1
@task
def task1() -> Union[int, str]:
return "hello world"
--> Outputs literal:
{
"union": {
val: <literal scalar string "hello world">
index: 1
}
}
@task
def task2(a Union[MyInt, int, str]):
...
task2(a=task1())
--> Inputs literal:
"a": {
"union": {
val: <literal scalar string "hello world">
index: 2, <<<<--- this is figured out by the backend runtime
}
}
# example 2
@task
def task1() -> int:
return 5
--> Outputs literal:
{
<literal scalar int 5>
}
@task
def task2(a Union[MyInt, int, str]):
...
task2(a=task1())
--> Inputs literal:
"a": {
"union": {
val: <literal scalar int 5>
index: 1, <<<<--- this is figured out by the backend runtime
}
}
# example 3
@task
def task1() -> MyInt:
...
--> What will be in the LiteralType? will it just be an int?
@task
def task2(a Union[MyInt, int, str]):
...
task2(a=task1())
--> How will the backend compiler match... if both MyInt and int look exactly the same, the backend compiler will have to reject this as unambiguous. Is that what you are proposing?
# example 4
@task
def task1() -> Union[MyInt]:
return MyInt(5)
--> Outputs literal:
{
"union": {
val: <literal scalar int 5>
tag: "MyInt"
}
}
@task
def task2(a Union[MyInt, int, str]):
...
task2(a=task1())
--> Inputs literal:
"a": {
# the exact literal as output by task1:
"union": {
val: <literal scalar int 5>
tag: "MyInt"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment