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

(🐞) Bad error message when using Concatenate incorrectly #13518

Closed
KotlinIsland opened this issue Aug 26, 2022 · 3 comments · Fixed by #15905 · May be fixed by #13529
Closed

(🐞) Bad error message when using Concatenate incorrectly #13518

KotlinIsland opened this issue Aug 26, 2022 · 3 comments · Fixed by #15905 · May be fixed by #13529
Labels
bug mypy got something wrong diagnostics topic-paramspec PEP 612, ParamSpec, Concatenate topic-usability

Comments

@KotlinIsland
Copy link
Contributor

KotlinIsland commented Aug 26, 2022

Despite the fact that a good message is output afterwards, the initial error seems like nonsense: "first arg to Callable must be a parameter specification". Huh? it is a ParamSpec?! I presume that this is because the type becomes Any (from error) due to the args being invalid. At runtime the type here would be Never (because it would raise).

from typing import Concatenate, Callable, ParamSpec, TypeVar, Any

P = ParamSpec("P")

def f(fn: Callable[Concatenate[P, int], None]): ...
main.py:5: error: The first argument to Callable must be a list of types, parameter specification, or "..."
main.py:5: note: See https://mypy.readthedocs.io/en/stable/kinds_of_types.html#callable-types-and-lambdas
main.py:5: error: The last parameter to Concatenate needs to be a ParamSpec
Found 2 errors in 1 file (checked 1 source file)

playground

@KotlinIsland
Copy link
Contributor Author

@sobolevn Should the message The first argument to Callable must be a list of types, parameter specification, or "..." be updated to include Concatenate or do you think that Concatenate falls under "parameter specification"?

@sobolevn
Copy link
Member

do you think that Concatenate falls under "parameter specification"?

I think this is correct 🤔

@gandhis1
Copy link

Does MyPy actually support Concatenate? I attempted to use it, but it's rejecting my first parameter in Callable[Concatenate[Dict[str, sa.Table], P], sa.sql.expression.Selectable]

ilevkivskyi added a commit that referenced this issue Aug 19, 2023
Fixes #14761
Fixes #15318
Fixes #14656
Fixes #13518

I noticed there is a bunch of inconsistencies in `semanal`/`typeanal`
for ParamSpecs, so I decided do a small cleanup. Using this opportunity
I also allow `Concatenate[int, ...]` (with literal Ellipsis), and reduce
verbosity of some errors.

cc @A5rocks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong diagnostics topic-paramspec PEP 612, ParamSpec, Concatenate topic-usability
Projects
None yet
4 participants