You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This gives an error of "Argument 1 to "asynccontextmanager" has incompatible type "Callable[[int], Coroutine[Any, Any, AsyncIterator[int]]]"; expected "Callable[[int], AsyncIterator[Never]]"
Where the synchronous version checks fine.
Expected Behavior
I expect the async version to work the same as the sync version
Actual Behavior
Mypy reports and error
mypy test.py
test.py:5: error: Argument 1 to "asynccontextmanager" has incompatible type"Callable[[], Coroutine[Any, Any, AsyncIterator[int]]]"; expected "Callable[[], AsyncIterator[Never]]" [arg-type]
test.py:10: error: Argument 1 to "asynccontextmanager" has incompatible type"Callable[[int], Coroutine[Any, Any, AsyncIterator[int]]]"; expected "Callable[[int], AsyncIterator[Never]]" [arg-type]
Found 2 errors in 1 file (checked 1 source file)
Your Environment
Mypy version used: 1.10.0
Mypy command-line flags: mypy test.py
Mypy configuration options from mypy.ini (and other config files):
Python version used: Python 3.11.4
The text was updated successfully, but these errors were encountered:
Funny enough, the following typechecks (note how async disappears in overload stubs). This seems to be the same kind of problem as functions/methods and decorators: too much of "indirectly applied" stuff confuses the checker. In your original snippet, the function is "async twice": mypy thinks that it returns a Coroutine which, when awaited, produces an AsyncIterator. But this only happens when applying a decorator to overloaded definition (see the full playground, reveal_type produces a right type indeed).
Bug Report
When trying to annotate overloads for an asynccontextmanager, I think mypy incorrectly reports an invalid return type.
To Reproduce
This gives an error of "Argument 1 to "asynccontextmanager" has incompatible type "Callable[[int], Coroutine[Any, Any, AsyncIterator[int]]]"; expected "Callable[[int], AsyncIterator[Never]]"
Where the synchronous version checks fine.
Expected Behavior
I expect the async version to work the same as the sync version
Actual Behavior
Mypy reports and error
Your Environment
mypy test.py
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: