Improve error message when variable-length tuple annotation is required
Open
Nobody has claimed this yet.
feature
topic-error-reporting
topic-usability
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Mypy currently does not give a particularly friendly error message for this snippet of code:
test = (1, 2)
test += (3,) # error: Incompatible types in assignment (expression has type "Tuple[int, int, int]", variable has type "Tuple[int, int]")
What the user probably needs to do is to add a variable-length tuple annotation, e.g.
test: tuple[int, ...] = (1, 2)
test += (3,)
However, the error message gives no indication of that (on mypy 0.941).
Refs #10384
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.
Research direction
Start with the provided variable-length tuple reproducer and compare the current diagnostic with the suggested tuple[int, ...] annotation. Trace the type-checking path that reports the incompatible assignment, then add wording that points users toward a variable-length tuple annotation and verify it against this example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100