PrefectHQ
prefect
BlogDocsChangelog

Fix misleading pyright error when calling async task with wrong argument types

#19327
Comparing
fix-task-call-overload-ordering
(
50d1603
) with
main
(
7d86c93
)
CodSpeed Performance Gauge
0%
Untouched
2
Ignored
6

Benchmarks

Passed

bench_import_prefect_flow
benches/bench_import.py
CodSpeed Performance Gauge
0%
1.3 s1.3 s
bench_task_decorator
benches/bench_tasks.py
CodSpeed Performance Gauge
0%
456.7 µs458.3 µs

Ignored

bench_flow_call[options0]
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
+1%
168.3 ms166.4 ms
bench_flow_decorator
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
-1%
6.6 ms6.7 ms
bench_import_prefect
benches/bench_import.py
Ignored
CodSpeed Performance Gauge
0%
1 s1 s
bench_task_call
benches/bench_tasks.py
Ignored
CodSpeed Performance Gauge
-1%
162.8 ms164.7 ms
bench_flow_call[options1]
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
0%
107.4 ms107.3 ms
bench_task_submit
benches/bench_tasks.py
Ignored
CodSpeed Performance Gauge
-9%
5.8 ms6.4 ms

Commits

Click on a commit to change the comparison range
Base
main
7d86c93
-0.15%
Fix misleading pyright error when calling async task with wrong argument types When calling an async task with incorrect argument types, pyright would show a confusing error: "State[CoroutineType[...]] is not awaitable" instead of a normal argument type error. This happened because: 1. Task.__call__ lacked explicit overloads for async tasks (Task[P, Coroutine[Any, Any, R]]) 2. The return_state=True overload came before return_state=False 3. When pyright couldn't match argument types, it fell back to the *args overloads and picked the first match (return_state=True), inferring State[Coroutine[...]] Fix: - Add explicit Task[P, Coroutine[Any, Any, R]] overloads (matching submit/map) - Reorder overloads so return_state=False comes first (the default behavior) Now pyright shows normal argument type errors instead of the confusing "State is not awaitable" message. Closes #19326 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
50d1603
8 hours ago
by zzstoatzz
© 2025 CodSpeed Technology
Home Terms Privacy Docs