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

[Regression] Inconsistent error with ParamSpec #16058

Closed
cdce8p opened this issue Sep 6, 2023 · 2 comments · Fixed by #15913
Closed

[Regression] Inconsistent error with ParamSpec #16058

cdce8p opened this issue Sep 6, 2023 · 2 comments · Fixed by #15913
Labels
bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate

Comments

@cdce8p
Copy link
Collaborator

cdce8p commented Sep 6, 2023

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
@cdce8p cdce8p added the bug mypy got something wrong label Sep 6, 2023
@AlexWaygood AlexWaygood added the topic-paramspec PEP 612, ParamSpec, Concatenate label Sep 6, 2023
@ilevkivskyi
Copy link
Member

Yeah, it is really bad when switching some precise type to Any results in an error, but here it is kind of expected. There is this thing called infer_against_any (or similar), and its idea is that when we have Any actual, we should infer some very forgiving type. The problem is that inferring Any for _P creates a type that is not forgiving at all (if there is a prefix, because plain *args: Any, **kwargs: Any are special-cased). I guess this issue will be fixed by #15913 in its original form (btw could you please check if you will have time).

I am still hesitating about what to do about that PR, and @JukkaL decided to ignore me there, so I guess I will need to make the hard choice myself.

@cdce8p
Copy link
Collaborator Author

cdce8p commented Sep 7, 2023

Thanks for the reply! I did check #15913 with Home Assistant (where I also noticed this error). #15913 on it's own not fix it. However, I'm also not seeing any new regressions so should be fine from that POV.

BTW feel free to ping me if I should check a PR against the whole Home Assistant test suite. I've a branch setup to test it quite easily with all it's 1300+ requirements. Might sometimes be a good addition to the regular mypy primer result.

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

Successfully merging a pull request may close this issue.

3 participants