Confusing error message when calling a function with incorrect *args
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 38/100
Research direction
Reproduce the example in bad_starargs.py and compare mypy's current diagnostics with the proposed output. Trace the handling of the unpacked tuple and update the diagnostics so each mismatched element identifies its own argument, with a note showing the unpacked tuple type.
Written by the indexing model from the issue text.
Description
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]"
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 54
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python/mypy
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
bug topic-configuration topic-error-reporting
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
zostera/django-bootstrap4#894 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
use-agent-os/agent-os#3276 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
NousResearch/hermes-agent#117848 ·