Skip to content

ParamSpec + Generics false positive #14347

Closed
@Tinche

Description

@Tinche

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-paramspecPEP 612, ParamSpec, Concatenate

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions