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

Passing a list as an argument with * leads to confusing error #3224

Open
JelleZijlstra opened this issue Apr 23, 2017 · 3 comments
Open

Passing a list as an argument with * leads to confusing error #3224

JelleZijlstra opened this issue Apr 23, 2017 · 3 comments
Labels
topic-calls Function calls, *args, **kwargs, defaults topic-error-reporting How we report errors topic-usability

Comments

@JelleZijlstra
Copy link
Member

JelleZijlstra commented Apr 23, 2017

(Originally reported at python/typeshed#814, which gives an example from real code.)

def foo(a: int, b: str = '') -> None: ...

foo(1)  # OK
foo(*[1])  # E: Argument 1 to "foo" has incompatible type *List[int]; expected "str"

Ideally this shouldn't be an error at all (this works fine at runtime), but I imagine it's hard for mypy to accept this code since it doesn't know how long the list is. However, we could at least fix the error message, which talks about "argument 1" needing to be a str when really it's argument 2 that is the problem.

@gvanrossum
Copy link
Member

IIRC the argument numbers are for the call site, not the definition site. But regardless the error is horrible. (And indeed, mypy probably will never support this. It's also kind of silly. :-)

@elazarg
Copy link
Contributor

elazarg commented Apr 23, 2017

There is a confusion inside mypy about the terms Argument vs Parameter, but this case specifically gets it right.

@gvanrossum
Copy link
Member

(That confusion does not just exist inside mypy -- the whole world is inconsistent in its use of these terms. When the distinction is really important the only solution is to say "actual" vs. "formal" parameter, or if you want to be even clumsier but rely less on convention, you could say "call-site" vs. "definition-time" or something.)

@JelleZijlstra JelleZijlstra added the topic-calls Function calls, *args, **kwargs, defaults label Mar 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-calls Function calls, *args, **kwargs, defaults topic-error-reporting How we report errors topic-usability
Projects
None yet
Development

No branches or pull requests

4 participants