Skip to content

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

Open
@JelleZijlstra

Description

@JelleZijlstra

(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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions