mypy doesn't recognize incompatible type in Dict

Open
#2,538 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
devtools

Research direction

Reproduce the report with Python 3.5.2 and mypy 0.4.6 using the example in mypy_bug.py, then compare diagnostics for the two update() calls. The work is done when the incompatible key and value types are both reported consistently.

Written by the indexing model from the issue text.

Description

bug priority-1-normal

On windows,

python --version
Python 3.5.2

with the following mypy_bug.py:
from typing import Dict

CHESSDICT = {} # type: Dict[str, int]
CHESSDICT.update({("a", 1): "Rook"})
CHESSDICT.update({(0, 0): "Rook"})
for key in CHESSDICT:
print('position {0}, figure {1}'.format(key, CHESSDICT[key]))

python -m mypy -v .\mypy_bug.py
LOG: Mypy version 0.4.6
LOG: Parsing .\mypy_bug.py (mypy_bug)
LOG: Parsing C:\Users\user\venv\lib\mypy\typeshed\stdlib\3\typing.pyi (typing)
LOG: Parsing C:\Users\user\venv\lib\mypy\typeshed\stdlib\3\builtins.pyi (builtins)
LOG: Parsing C:\Users\user\venv\lib\mypy\typeshed\stdlib\3\sys.pyi (sys)
LOG: Parsing C:\Users\user\venv\lib\mypy\typeshed\stdlib\3\abc.pyi (abc)
LOG: Parsing C:\Users\user\venv\lib\mypy\typeshed\stdlib\3\types.pyi (types)
LOG: Parsing C:\Users\user\venv\lib\mypy\typeshed\stdlib\3_importlib_modulespec.pyi (_importlib_modulespec)
LOG: Loaded graph with 7 nodes
LOG: Found 2 SCCs; largest has 6 nodes
LOG: Processing SCC of size 6 (_importlib_modulespec types abc typing sys builtins) as inherently stale
LOG: Processing SCC singleton (mypy_bug) as inherently stale
LOG: No fresh SCCs left in queue
LOG: Build finished in 0.579 seconds with 7 modules, 1708 types, and 1 errors
mypy_bug.py:5: error: List item 0 has incompatible type "Tuple[Tuple[int, int], str]"

The line no 5 is recognised correctly as incompatible with Dict[str, int]
But line no 4 is not recognised, but in my opinion Dict[str, int] != Dict[Tuple[str, int], str]

Dominant language
Python
Stars
20.6k
Forks
3.3k
Avg merge
1d 18h
Merged PRs (30d)
54

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python/mypy

All issues in python/mypy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.