Skip to content
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

Collection of Generic[T] and Generic[real type] becomes Collection[object] #8947

Closed
crusaderky opened this issue Jun 4, 2020 · 1 comment

Comments

@crusaderky
Copy link
Contributor

crusaderky commented Jun 4, 2020

import asyncio
from typing import Awaitable, TypeVar

T = TypeVar("T")


async def f(aw: Awaitable[T], t: asyncio.Task[None]) -> None:
    futs = {aw, t}
    await asyncio.wait(futs)
    reveal_type(futs)

mypy 0.780 output:

9: error: Argument 1 to "wait" has incompatible type "Set[object]"; expected "Iterable[Union[Future[<nothing>], Generator[Any, None, <nothing>], Awaitable[<nothing>]]]"
10: note: Revealed type is 'builtins.set[builtins.object*]'
Found 1 error in 1 file (checked 1 source file)

Expected output:

10: note: Revealed type is 'builtins.set[Union[Awaitable[T], asyncio.Task[None]]]'

The issue disappears if I either

  • replace Awaitable[T] with Awaitable[None]
  • replace Task[None] with Task[Any]

This issue is not new in 0.780; however starting from 0.780 asyncio.create_task propagates the return type of its input whereas before it was returning Task[Any], so it makes the issue crop up.

@JukkaL
Copy link
Collaborator

JukkaL commented Jun 8, 2020

Mypy can't infer a good enough type for futs. The recommended workaround is to add a type annotation for futs. This is basically an instance of #3816.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants