Argument of type "PrefectFuture[int, Sync]" cannot be assigned to parameter "i" of type "int" in function "__call__"
See original GitHub issueDescription
pyright error:
basic_flow.py:12:18 - error: Argument of type "PrefectFuture[int, Sync]" cannot be assigned to parameter "i" of type "int" in function "__call__"
"PrefectFuture[int, Sync]" is incompatible with "int" (reportGeneralTypeIssues)
mypy error:
basic_flow.py:12: error: No overload variant of "__call__" of "Task" matches argument type "PrefectFuture[None, Literal[False]]"
basic_flow.py:12: note: Possible overload variants:
basic_flow.py:12: note: def __call__(self, i: int) -> PrefectFuture[None, Literal[False]]
basic_flow.py:12: note: def __call__(self, i: int) -> Awaitable[PrefectFuture[<nothing>, Literal[True]]]
Reproduction / Example
basic_flow.py:
from prefect import flow, get_run_logger, task
from prefect.futures import PrefectFuture
from prefect.utilities.asyncio import Sync
@flow
def add_flow(i: int) -> PrefectFuture[int, Sync]:
# result is PrefectFuture[int, Sync]
result = add_one(i)
# passing the result future will resolve to its int value
print_result(result) # <--- line 12: pyright/mypy errors here
return result
@task
def add_one(i: int) -> int:
return i + 1
@task
def print_result(i: int) -> None:
logger = get_run_logger()
logger.info(f"print_result: {i=}")
if __name__ == "__main__":
add_flow(1)
prefect 2.0b8
Issue Analytics
- State:
- Created a year ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
python - Pylance: Argument of type "int" cannot be assigned to ...
I don't understand why the int 24 cannot be assigned to Literal int with the same value. What is the correct way to...
Read more >Common issues and solutions - mypy 0.991 documentation
There are several common reasons why obviously wrong code is not flagged as an error. The function containing the error is not annotated....
Read more >Generics - Microsoft MakeCode Arcade
Once we've written the generic identity function, we can call it in one of two ways. The first way is to pass all...
Read more >tf.function | TensorFlow v2.11.0
Compiles a function into a callable TensorFlow graph. ... each specialized to arguments with different data types or shapes, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The comment above still stands:
We automatically coerce futures into values for you, but that kind of magic isn’t supported by type checkers. I’m not sure this is something we can reasonably address. To support this, we’d need to update the input signature of your task to make each argument a
Union[Future[T], T]
. I do not believe this is possible with Python parameter specs yet. We may be able to write a mypy plugin to make this feasible, but pyright does not support plugins.