question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Argument of type "PrefectFuture[int, Sync]" cannot be assigned to parameter "i" of type "int" in function "__call__"

See original GitHub issue

Description

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:open
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
madkinszcommented, Sep 22, 2022

The comment above still stands:

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.

1reaction
madkinszcommented, Jul 10, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >
Google Python Style Guide
Style guides for Google-originated open-source projects.
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found