Skip to content

[Regression] Inconsistent error with ParamSpec #16058

Closed
@cdce8p

Description

@cdce8p

Bug Report
Notice this while testing the master branch. I bisected the regression to

/CC @ilevkivskyi

To Reproduce

https://mypy-play.net/?mypy=master&python=3.11&gist=b8554f05b565ff448d1a291b3dbc38c3

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

_P = ParamSpec("_P")
_R = TypeVar("_R")

class A: ...
a = A()

def a_func(
    func: Callable[Concatenate[A, _P], _R],
) -> Callable[Concatenate[Any, _P], _R]:

    def wrapper(_: Any, /, *args: _P.args, **kwargs: _P.kwargs) -> _R:
        return func(a, *args, **kwargs)

    return wrapper


def filter(a, *args):
    ...


x: Any
y: object

a_func(filter)
x = a_func(filter)  # error
y = a_func(filter)

Expected Behavior
no error

Actual Behavior

main.py:28: error: Argument 1 to "a_func" has incompatible type "Callable[[Any, VarArg(Any)], Any]"; expected "Callable[[A, VarArg(Any), KwArg(Any)], Any]"  [arg-type]
main.py:28: note: This is likely because "filter" has named arguments: "a". Consider marking them positional-only
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: mypy 1.7.0+dev.c0906408c10d24d748711fa24be5befb2c794d4c (compiled: no)
  • Python version used: 3.11.5

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