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

fix overloads for wait_for and return_state in Task.__call__ #16547

Merged
merged 11 commits into from
Dec 30, 2024

Conversation

zzstoatzz
Copy link
Collaborator

@zzstoatzz zzstoatzz commented Dec 30, 2024

adds an overload to make the type checker handle wait_for when calling tasks directly, pyright complains on main

also makes various Dict -> dict changes and adds a private alias to make the overloads as shown by IDE easier to grok

main

image

this branch

image

example

from prefect import flow, task


@task
def double(x: int) -> int:
    return x * 2


@task
def cast_to_float(x: int) -> float:
    return float(x)


@flow
def flow_with_task() -> float:
    result = double(1)
    other_result = cast_to_float(2, wait_for=[result])
    state = cast_to_float(3, wait_for=[other_result], return_state=True)
    last_value = cast_to_float(4, wait_for=[state.result()], return_state=False)
    return last_value

Copy link

codspeed-hq bot commented Dec 30, 2024

CodSpeed Performance Report

Merging #16547 will not alter performance

Comparing dunder-call-wait-for-typing (bd3c871) with main (0049987)

Summary

✅ 3 untouched benchmarks

@zzstoatzz zzstoatzz force-pushed the dunder-call-wait-for-typing branch from 8324e01 to 0a3fa15 Compare December 30, 2024 04:16
@zzstoatzz zzstoatzz added the development Tech debt, refactors, CI, tests, and other related work. label Dec 30, 2024
@zzstoatzz zzstoatzz changed the title add overload for wait_for_ in Task.__call__ fix overloads for wait_for in Task.__call__ Dec 30, 2024
@zzstoatzz zzstoatzz changed the title fix overloads for wait_for in Task.__call__ fix overloads for wait_for and return_state in Task.__call__ Dec 30, 2024
@zzstoatzz zzstoatzz marked this pull request as ready for review December 30, 2024 17:02
Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

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

One question about using forward refs in the task engine for stuff from prefect.tasks, but otherwise this is great!

src/prefect/task_engine.py Outdated Show resolved Hide resolved
@zzstoatzz zzstoatzz merged commit 9ac5c5e into main Dec 30, 2024
38 checks passed
@zzstoatzz zzstoatzz deleted the dunder-call-wait-for-typing branch December 30, 2024 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development Tech debt, refactors, CI, tests, and other related work.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants