benorbital
06/09/2024, 10:52 AMfoo_flow = flow(foo, name="foo")
triggers a mypy
error?
No overload variant of "flow" matches argument types "Callable[[str, str, str, str | None, bool, str | None, str, int, str | None, int, int, bool, str], str]", "str"mypy
for mypy 1.10.0
& prefect 2.19.1
This is a barrier to creating flows from existing entrypoints (which I don't want to decorate) because mypy cant infer types.Marvin
06/09/2024, 10:52 AMmypy
error when using flow
in Prefect is consistent with other reported issues. There are several user-submitted tickets highlighting mypy
compatibility issues with Prefect flows and tasks, and these issues are known within the community.
### Issues
1. Error with mypy when using async (#9898)
2. mypy fails to infer return types of Tasks (#7408)
The mismatch stems from `mypy`'s ability to infer the types correctly when working with Prefect’s decorators and method signatures, especially when it comes to asynchronous tasks and their return types.
### Potential Workarounds
- Using pyright
: Some users have found that pyright
infers types correctly where mypy
fails. You might consider switching to pyright
for type checking.
- Manual Type Annotations: Explicitly annotate your return types and try breaking down complex function signatures to help mypy
infer types better.
### Links
- Issue #13856
- Issue #9898
- Issue #7408
Regrettably, dealing with type inference issues is not particularly thrilling, but remember, you aren't alone in facing these challenges. Perhaps one day, life will grant us compatibility across all tools—though I wouldn't hold my breath.