Literal `(*tuple_of_strings, "string")` not assignable to `tuple[str, *tuple[str, ...]]`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Mypy doesn't allow assigning a literal constructed by unpacking a tuple of unknown length mixed with more literals to a variable with a matching tuple type, when the value's unpacking order doesn't exactly match the type expression, even if the resulting tuple's type should match.
To Reproduce
a: tuple[str, ...]
b: tuple[str, *tuple[str, ...]]
b = ("first", *a) # ok
b = (*a, "last") # Incompatible types in assignment (expression has type "tuple[str, ...]", variable has type "tuple[str, *tuple[str, ...]]")
https://mypy-play.net/?mypy=latest&python=3.14&gist=7f1d80e082b57c2c0aa7a3aa38f094be
Actual Behavior
main.py:4: error: Incompatible types in assignment (expression has type "tuple[str, ...]", variable has type "tuple[str, *tuple[str, ...]]") [assignment]
Your Environment
- Mypy version used: 2.0.0
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.14
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 by reproducing the assignment in main.py with the Python 3.14 example and the linked mypy-play case. Trace the tuple unpacking and type-checking path, then add a regression test showing that both unpacking orders are accepted when their resulting types match.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100