Skip to content
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

Improve task type hint #1711

Merged
merged 5 commits into from
Jun 27, 2023
Merged

Improve task type hint #1711

merged 5 commits into from
Jun 27, 2023

Conversation

pingsutw
Copy link
Member

TL;DR

Before:
image

After:
image

Type

  • Bug Fix
  • Feature
  • Plugin

Are all requirements met?

  • Code completed
  • Smoke tested
  • Unit tests added
  • Code documentation added
  • Any pending items have an associated Issue

Complete description

^^^

Tracking Issue

NA

Follow-up issue

NA

Signed-off-by: Kevin Su <[email protected]>
@kumare3
Copy link
Contributor

kumare3 commented Jun 26, 2023

Interesting

@eapolinario
Copy link
Collaborator

Isn't this essentially voiding any guarantee that tools like mypy or pyright could give users?

Signed-off-by: Kevin Su <[email protected]>
wild-endeavor
wild-endeavor previously approved these changes Jun 26, 2023
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
wild-endeavor
wild-endeavor previously approved these changes Jun 26, 2023
@eapolinario
Copy link
Collaborator

mypy still complains about tasks invoked in workflows:

❯ cat workflows/example.py
import typing
from flytekit.core.task import task
from flytekit.core.workflow import workflow

@task
def say_hello(name: str) -> str:
    return f"hello {name}!"

@task
def greeting_length(greeting: str) -> int:
    return len(greeting)

@workflow
def wf(name: str) -> typing.Tuple[str, int]:
    greeting = say_hello(name=name)
    greeting_len = greeting_length(greeting=greeting)
    return greeting, greeting_len

❯ mypy workflows/example.py
workflows/example.py:17: error: Incompatible return value type (got "tuple[Promise | VoidPromise | tuple[Any, ...] | None, Promise | VoidPromise | tuple[Any, ...] | None]", expected "tuple[str, int]")  [return-value]
Found 1 error in 1 file (checked 1 source file)

Signed-off-by: Kevin Su <[email protected]>
@pingsutw
Copy link
Member Author

image

@eapolinario
Copy link
Collaborator

Nevermind. I tested this by producing a wheel and installing it in a separate venv, but probably messed up on the way. Sorry for the false alarm!

Copy link
Collaborator

@eapolinario eapolinario left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome!

Should we also add a py.typed?

@wild-endeavor
Copy link
Contributor

Related to #1631

@pingsutw
Copy link
Member Author

Should we also add a py.typed?

I'm not sure if we have fixed all the mypy issues. Will do more testing for mypy and add it.

@pingsutw pingsutw merged commit 1052af8 into master Jun 27, 2023
@eapolinario
Copy link
Collaborator

Should we also add a py.typed?

I'm not sure if we have fixed all the mypy issues. Will do more testing for mypy and add it.

there's at least one case where this is going to break badly: NamedTuple. But that shouldn't stop us from shipping this (i.e. we can document this limitation for the time being).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants