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

ParamSpec doesn't handle out-of-order kwargs for callable protocol #15984

Closed
koogoro opened this issue Aug 29, 2023 · 1 comment · Fixed by #15986
Closed

ParamSpec doesn't handle out-of-order kwargs for callable protocol #15984

koogoro opened this issue Aug 29, 2023 · 1 comment · Fixed by #15986
Labels
bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate

Comments

@koogoro
Copy link
Collaborator

koogoro commented Aug 29, 2023

Bug Report

If you use a ParamSpec to accept a callable and its arguments, and supply keyword args in a different order than they appear in the arguments, mypy reports an error:
https://mypy-play.net/?mypy=master&python=3.11&gist=56911342c8a4d3326da4cc1265f1a156

This didn't happen on the last release, and in fact didn't happen as recently as 5d909f1. It does seem to happen only for callable protocols and not for functions.

Actual Behavior

main.py:12: error: Argument 1 to "g" has incompatible type "A"; expected "Callable[[int, str], None]"  [arg-type]
main.py:12: note: "A.__call__" has type "Callable[[Arg(str, 'x'), Arg(int, 'y')], None]"
@koogoro koogoro added bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate labels Aug 29, 2023
@ilevkivskyi
Copy link
Member

Yeah, this is caused by my PR. I will take a look later today (It is sad we don't have something like get_proper_type() and plugin for CallableType, maybe we should write one, but I guess it may be a pain to use, since we don't have checkmember infra available in many places, so it comes back again to #7724)

hauntsaninja pushed a commit that referenced this issue Aug 30, 2023
Fixes #15984

Fix is straightforward, `ParamSpec` inference special-casing should put
instances with `__call__` and callable types on same ground.
koogoro pushed a commit that referenced this issue Sep 2, 2023
Fixes #15984

Fix is straightforward, `ParamSpec` inference special-casing should put
instances with `__call__` and callable types on same ground.
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.

2 participants