wrong inference with nested unpacking
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Unpacking a list into multiple variables when the list itself is (partially) created by unpacking another iterable the type inference is faulty
To Reproduce
from typing import reveal_type
text = "some\nstuff"
version, desc, *_ = [*text.split(sep="\n", maxsplit=1), None, None]
reveal_type(version) # str
reveal_type(desc) # None
Expected Behavior
Mypy infers version and desc and str | None (if you want to go very far you can even infer version as str because str.split never returns an empty list, but that is not my expectation)
Actual Behavior
Mypy infers version as str and desc as None
Your Environment
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 nested-unpacking reproducer in the mypy playground and inspect how reveal_type reports version and desc. Trace the type inference for the starred list expression and tuple unpacking; done when both variables are inferred as str | None in the reported example.
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
- Mostly clear
- Newbie friendliness
- 48/100