UnionType of Callable[P, Awaitable[T]] | Callable[P, T]
not being matched by async function.
#16646
Labels
bug
mypy got something wrong
Bug Report
I'm trying to annotate a decorator that can take both async and normal functions using
The Callable[P, Awaitable[T]] variant does not match when using the decorator with an async function and instead raises an error
"Argument 1 to "decorator" has incompatible type "Callable[[int], Coroutine[Any, Any, str]]"; expected "Callable[[VarArg(Never), KwArg(Never)], Awaitable[Never]] | Callable[[VarArg(Never), KwArg(Never)], Never]" [arg-type]"
This may be related to #16451 which was fixed by 1.7.1
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.11&flags=new-type-inference&gist=c5255c4185cf954aa32bc8f8b2c04c10
Expected Behavior
Both sync and async should be type matched correctly
Actual Behavior
I get a strange error with the async variant (main.py:61: error: Argument 1 to "decorator" has incompatible type "Callable[[int], Coroutine[Any, Any, str]]"; expected "Callable[[VarArg(Never), KwArg(Never)], Awaitable[Never]] | Callable[[VarArg(Never), KwArg(Never)], Never]" [arg-type])
Your Environment
Also replicated in the playground with 1.7.1 compiled and Python 3.11 and 3.12.
The text was updated successfully, but these errors were encountered: