Literal slicing of a variable-length tuple does not work
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Slicing a variable-length tuple with a literal int does not reveal as a corresponding fixed-length tuple. This causes both false negative, where no error reported with incorrect unpacking, and false positive of incompatible type with say return values.
To Reproduce
def foo(x: tuple[str, ...]) -> tuple[str, str]:
a, b = x[:3]
return x[:2]
Expected Behavior
a, b = x[:3] should give an error of too many values to unpack, return x[:2] should pass with no error.
Actual Behavior
a, b = x[:3] gives no error, return x[:2] says incompatible return value type.
Your Environment
- Mypy version used: 0.961
- Python version used: 3.10
- Operating system and version: macOS 12.4
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 provided tuple-slicing example with mypy 0.961 on Python 3.10 and inspect the type-checking path for literal slices of variable-length tuples. Done means reporting an error for unpacking x[:3] into two values while accepting x[:2] as tuple[str, str].
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100