Skip to content

ParamSpec + Generics doesn't work #14968

Closed
@klen

Description

@klen

Bug Report

Mypy doesn't process ParamSpec correctly.

To Reproduce

from __future__ import annotations

from collections.abc import Callable
from typing import Any, Generic, ParamSpec, TypeVar

P = ParamSpec("P")
TVFn = TypeVar("TVFn", bound=Callable[..., Any])


class Example(Generic[TVFn]):
    def __init__(self, fn: TVFn):
        self.fn = fn

    def __call__(self: Example[Callable[P, Any]], *args: P.args, **kwargs: P.kwargs):
        ...


def test_fn(a: int, b: str) -> None:
    ...


example = Example(test_fn)
example()  # mypy doesn't show an error for this call
example(1, "b") # mypy show errors for this call

Expected Behavior

example()  # show missing arguments here
example(1, "b")  # pass here

Actual Behavior

Mypy output

paramspec.py:24: error: Argument 1 to "__call__" of "Example" has incompatible type "int"; expected <nothing>  [arg-type]
paramspec.py:24: error: Argument 2 to "__call__" of "Example" has incompatible type "str"; expected <nothing>  [arg-type]
Found 2 errors in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.1.1
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.11.2

BTW: in pyright this code working fine

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