Indexing tuple with `slice` object results in wrong type
Open
Nobody has claimed this yet.
bug
priority-1-normal
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Example:
x = (1, 2, 3)
y = x[1:3]
z = x[slice(1, 3)]
reveal_locals()
Output from mypy:
note: Revealed local types are:
note: x: Tuple[builtins.int, builtins.int, builtins.int]
note: y: Tuple[builtins.int, builtins.int]
note: z: builtins.int
I believe z should also have type Tuple[builtins.int, builtins.int], or at a minimum Tuple[builtins.int, ...].
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 running the provided tuple-indexing example with mypy and compare the inferred types for slice syntax and an explicit slice object. Trace the type-checking path for tuple indexing, then add coverage showing that z is inferred as a tuple and confirm the revealed type matches the intended result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100