Skip to content

ParamSpec + Generics false positive #14347

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

Closed
Tinche opened this issue Dec 26, 2022 · 1 comment
Closed

ParamSpec + Generics false positive #14347

Tinche opened this issue Dec 26, 2022 · 1 comment
Labels
bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate

Comments

@Tinche
Copy link
Contributor

Tinche commented Dec 26, 2022

Bug Report

Hello. Here's something I stumbled upon implementing an asyncio thing. It looks like an issue with ParamSpec and/or generics to me.

To Reproduce

from asyncio import AbstractEventLoop, Task, get_running_loop
from contextvars import copy_context


loop: AbstractEventLoop = get_running_loop()


async def to_run() -> int:
    return 1


task: Task[int]

# Works, correctly:
task = loop.create_task(to_run())

# Error, incorrectly:
task = copy_context().run(loop.create_task, to_run())

Expected Behavior

The example should type-check.

Actual Behavior

Mypy reports the following:

a02.py:18: error: Argument 1 to "run" of "Context" has incompatible type "Callable[[Union[Coroutine[Any, Any, _T], Generator[Any, None, _T]], DefaultNamedArg(Optional[str], 'name'), DefaultNamedArg(Optional[Context], 'context')], Task[_T]]"; expected "Callable[[Union[Coroutine[Any, Any, _T], Generator[Any, None, _T]], DefaultNamedArg(Optional[str], 'name'), DefaultNamedArg(Optional[Context], 'context')], Task[int]]"  [arg-type]
a02.py:18: error: Argument 2 to "run" of "Context" has incompatible type "Coroutine[Any, Any, int]"; expected "Union[Coroutine[Any, Any, _T], Generator[Any, None, _T]]"  [arg-type]
Found 2 errors in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: mypy 0.991 (compiled: yes)
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.11.1
@Tinche Tinche added the bug mypy got something wrong label Dec 26, 2022
@Tinche Tinche changed the title ParamSpec + Generics false negative ParamSpec + Generics false positive Dec 26, 2022
@JelleZijlstra JelleZijlstra added the topic-paramspec PEP 612, ParamSpec, Concatenate label Dec 27, 2022
@ilevkivskyi
Copy link
Member

This example works correctly on master with --new-type-inference, likely fixed by #15837

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate
Projects
None yet
Development

No branches or pull requests

3 participants