mypy rejects unpacking into same variable
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
I believe the following code should be fine, however mypy rejects the case where we're unpacking into the variable which was expanded:
foo: tuple[int, ...] = ()
# Ok
bar, *quox = foo
# Incompatible types in assignment (expression has type "List[int]", variable has type "Tuple[int, ...]") [assignment]
bar, *foo = foo
There are a number of similar issues reported, the closest being https://github.com/python/mypy/issues/9706, however I believe this is distinct as it reproduces when the generic type is int (though my original code was using str). This suggests a different root cause.
Your Environment
- Mypy version used: 1.0.1
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.10
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 reported Python 3.10 snippet with mypy 1.0.1 and tracing how unpacking assignment is checked when the expanded variable is also the source. Add a regression test for this case, ensuring the same-variable unpacking is accepted while incompatible assignments remain diagnosed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100