Hi there, I’m playing with Prefect Python SDK. It ...
# ask-community
n
Hi there, I’m playing with Prefect Python SDK. It seems the
task
decorator is causing some issues with
mypy
. 🧵
minimal example:
Copy code
from typing import Any, cast

import httpx
from prefect import flow, task


@task(retries=3)
def call(url: str) -> dict[str, Any]:
    response = httpx.get(url)
    if response.status_code >= 400:
        raise Exception()
    return cast(dict[str, Any], response.json())


@task
def parse(response: dict[str, Any]) -> str:
    return cast(str, response["fact"])


@flow
def run_demo_prefect(url: str) -> None:
    fact_response = call(url)
    parse(fact_response)


if __name__ == "__main__":
    run_demo_prefect("<https://catfact.ninja/fact>")
mypy
complains with
Copy code
example.py:23: error: No overload variant of "__call__" of "Task" matches argument type "None"  [call-overload]
example.py:23: note: Possible overload variants:
example.py:23: note:     def __call__(self, response: Dict[str, Any]) -> None
example.py:23: note:     def __call__(self, response: Dict[str, Any]) -> str
example.py:23: note:     def __call__(self, *args: Any, return_state: Literal[True], **kwargs: Any) -> State[str]
Python 3.11 Prefect 2.10.11 mypy 1.3.0
d
any help with this? seriously struggling to make mypy happy
n
hmm, running your example I am getting
Copy code
❯ mypy mypytest.py --follow-imports skip
Success: no issues found in 1 source file
do you need to check that prefect internals are mypy compliant or just your code?
n
just my code
which version are u using?