You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
diff --git a/src/prefect/tasks.py b/src/prefect/tasks.py
index 7763722573..9b291f7a66 100644
--- a/src/prefect/tasks.py+++ b/src/prefect/tasks.py@@ -965,7 +965,7 @@ class Task(Generic[P, R]):
def __call__(
self: "Task[P, NoReturn]",
*args: P.args,
- return_state: Literal[False],+ return_state: Literal[False] = False,
wait_for: Optional[OneOrManyFutureOrResult[Any]] = None,
**kwargs: P.kwargs,
) -> None:
@@ -977,20 +977,22 @@ class Task(Generic[P, R]):
def __call__(
self: "Task[P, R]",
*args: P.args,
- return_state: Literal[True],- wait_for: Optional[OneOrManyFutureOrResult[Any]] = None,
**kwargs: P.kwargs,
- ) -> State[R]:+ ) -> R:
...
+ # Keyword parameters `return_state` and `wait_for` aren't allowed after the+ # ParamSpec `*args` parameter, so we lose return type typing when either of+ # those are provided.+ # TODO: Find a way to expose this functionality without losing type information
@overload
def __call__(
self: "Task[P, R]",
*args: P.args,
- return_state: Literal[False],+ return_state: Literal[True] = True,
wait_for: Optional[OneOrManyFutureOrResult[Any]] = None,
**kwargs: P.kwargs,
- ) -> R:+ ) -> State[R]:
...
If I switch the order of these overloads it works as expected for us, however I don't know if that would break anything else. There's also a TODO comment here indicating that additional work needs to be done.
# Keyword parameters `return_state` and `wait_for` aren't allowed after the# ParamSpec `*args` parameter, so we lose return type typing when either of# those are provided.# TODO: Find a way to expose this functionality without losing type information@overloaddef__call__(
self: "Task[P, R]",
*args: P.args,
return_state: Literal[True] =True,
wait_for: Optional[OneOrManyFutureOrResult[Any]] =None,
**kwargs: P.kwargs,
) ->State[R]: ...
@overloaddef__call__(
self: "Task[P, R]",
*args: P.args,
return_state: Literal[False] =False,
wait_for: Optional[OneOrManyFutureOrResult[Any]] =None,
**kwargs: P.kwargs,
) ->R: ...
Version info
❯ prefect version
Version: 3.2.9
API version: 0.8.4
Python version: 3.12.8
Git commit: 27eb408c
Built: Fri, Feb 28, 2025 8:12 PM
OS/Arch: darwin/arm64
Profile: ephemeral
Server type: server
Pydantic version: 2.10.6
Integrations:
prefect-redis: 0.2.2
Additional context
No response
The text was updated successfully, but these errors were encountered:
Bug summary
Between Prefect 3.1.14 and 3.1.15 there was a change in the overload definitions for
@task
which resulted mypy issues within our codebase.The code looks like this:
The mypy errors we are are seeing from 3.1.15 and onward look like this:
The change was introduced in this PR: #16891.
If I switch the order of these overloads it works as expected for us, however I don't know if that would break anything else. There's also a TODO comment here indicating that additional work needs to be done.
Version info
Additional context
No response
The text was updated successfully, but these errors were encountered: