Incompatible types in assignment for `dict[key] = tmp = value` and nested structures
Open
Nobody has claimed this yet.
bug
false-positive
priority-2-low
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
I have Python2 code building some nested structures like lists/tuples/sets/dicts in dicts. For populating the nested structure I keep a temporary reference, which mypy fails to parse if the (untyped) temporary reference is not the first variable being assigned:
#!/usr/bin/python2.7
from typing import Dict, Set # noqa
x = {} # type: Dict[str, Set[str]]
z = x[''] = set() # okay
x[''] = y = set() # fail: Incompatible types in assignment (expression has type "Set[<nothing>]", target has type "Set[str]")
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 minimal Python 2.7 reproduction shown in the issue and compare the two chained-assignment forms. Trace how mypy infers the untyped temporary in each case; done means the second form is accepted consistently with the first without weakening the declared Dict[str, Set[str]] checking.
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
- 35/100