Skip to content

Confusing error message when calling a function with incorrect *args #4771

@msullivan

Description

@msullivan

When typechecking this:

def foo(x: int, y: str) -> None: pass
t = ('hi', 12)
foo(*t)

mypy reports

bad_starargs.py:3: error: Argument 1 to "foo" has incompatible type "*Tuple[str, int]"; expected "int"
bad_starargs.py:3: error: Argument 1 to "foo" has incompatible type "*Tuple[str, int]"; expected "str"

This is not great, since Tuple[str, int] isn't being compared to something, and while it appears in argument position 1, the type mismatches don't necessarily.

A better error message might be something like:

bad_starargs.py:3: error: Argument 1 to "foo" has incompatible type "str"; expected "int"
bad_starargs.py:3: note: while unpacking "*Tuple[str, int]"
bad_starargs.py:3: error: Argument 2 to "foo" has incompatible type "int"; expected "str"
bad_starargs.py:3: note: while unpacking "*Tuple[str, int]"

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions