-
Notifications
You must be signed in to change notification settings - Fork 767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Awaitable[Any]" is incompatible with "Coroutine[Any, Any, Any]" #184
Comments
Thanks for the bug report. Currently, Pylance infers the type |
This didn't quite make it into 2020.7.4, but will be in the next release. |
This issue has been fixed in version 2020.8.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202080-5-august-2020 |
Shouldn't this PR make the following valid? import typing as t
import asyncio
import functools
from concurrent.futures import Executor
from typing_extensions import ParamSpec
T = t.TypeVar("T")
P = ParamSpec("P")
def to_async(executor: t.Optional[Executor] = None):
def decorator(f: t.Callable[P, T]) -> t.Callable[P, t.Awaitable[T]]:
@functools.wraps(f)
def wrapper(*args: P.args, **kwargs: P.kwargs) -> t.Awaitable[T]:
loop = asyncio.get_event_loop()
return loop.run_in_executor(executor, functools.partial(f, *args, **kwargs))
return wrapper
return decorator
@to_async()
def sync(name: str) -> int:
return 2
async def main():
return await sync("test")
asyncio.run(main())
asyncio.run(sync("test")) # <-- "Awaitable[int]" is incompatible with "Coroutine[Any, Any, _T@run]" |
@nixfixbix, no, your code sample should result in a type violation error. The title of this issue is misleading because it doesn't describe the underlying cause of the problem the OP was seeing. The fix was to infer a return type of |
Thanks @erictraut - I don't understand how you always are able to reply so quickly and great answers too. Great job! 👏🏼 |
Environment data
Expected behaviour
Awaitable[Any]
should be compatible withCoroutine[Any, Any, Any]
. Or, potentially, instead of being anAwaitable[Any]
an un-awaited coroutine should beCoroutine[Any, Any, Any]
? For comparison, I do not believe mypy views the below code snippet as an error, though it is possible I'm using mypy incorrectly.Details from mypy are available here: https://mypy.readthedocs.io/en/stable/more_types.html#async-and-await
Actual behaviour
Pylance throws an error:
Logs
I don't think logs are necessary for this issue, can provide if requested.
Code Snippet / Additional information
Here's a silly example that just does some basic introspection of a passed coroutine. It runs as-is if copied into ipython, but pylance flags with the error from above on the last line,
inner(1, "test")
. I don't have much experience with mypy but I do not believe it is flagging the same line as an error.The text was updated successfully, but these errors were encountered: