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

Function parameters are not hinted at since the Flow comes back as Any type variable. #5354

Closed
scoussens opened this issue Jan 21, 2022 · 3 comments
Labels
status:stale This may not be relevant anymore

Comments

@scoussens
Copy link

Description

With modern development tooling, when you implement a function, you will see a list of variables the function expects.

ApplicationFrameHost_e28wGWP8zO

When you write a function as a Task using the Prefect @task decorator, it hides the parameters since the return type is 'FunctionTask'.

image

Expected Behavior

The IDE should be able to show the expected parameters, even if they have to be annotated in the @task decorator somehow. This way when building tasks (especially a large number of tasks), you can see what the task expects when you attempt to use it in your flow.

Reproduction

Create a Task function (decorated with @task), then when using it in the Flow you will not see any hints as to what variables it expects, or if any at all.

Environment

Linux ubuntu 20.04 docker container, using visual studio code, with python extension installed.

Optionally run prefect diagnostics from the command line and paste the information here. -->
{
"config_overrides": {},
"env_vars": [
"PREFECT__CLOUD__USE_LOCAL_SECRETS",
"PREFECT__CLOUD__API_KEY"
],
"system_information": {
"platform": "Linux-5.10.16.3-microsoft-standard-WSL2-x86_64-with-glibc2.28",
"prefect_backend": "cloud",
"prefect_version": "0.15.12",
"python_version": "3.9.6"
}
}

@zanieb
Copy link
Contributor

zanieb commented Jan 21, 2022

Hi! This is primarily a consequence of the novelty of typing in Python. The language has only recently added support for maintaining type signatures on decorated functions like this. Prefect Orion supports this, but it only works with pyright (and consequently, VSCode) and it was a lot of work. It's actually not possible with mypy as they haven't added support for the ParamSpec type yet. We'd have to write a mypy extension, but I'd rather wait for real support to come upstream.

It is likely that our team will focus on supporting this cleanly in Orion rather than attempting to add compatibility here. I'd be willing to review a PR that backports the Orion implementation though.

@carderne
Copy link
Contributor

Sorry to resuscitate, do you know if this is fixed yet in mypy/prefect?

Using Python 3.10.9, mypy 0.991 and Prefect 2.7.3.
Code below shows res having type None.

from prefect import flow, task

@task
def task_one() -> int:
    return 1

@flow
def main() -> None:
    res = task_one()
    reveal_type(res)

@github-actions
Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. To keep this issue open remove stale label or comment.

@github-actions github-actions bot added the status:stale This may not be relevant anymore label Mar 13, 2023
@zanieb zanieb closed this as not planned Won't fix, can't repro, duplicate, stale Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:stale This may not be relevant anymore
Projects
None yet
Development

No branches or pull requests

3 participants