Closed
Description
Bug Report
Mypy is treating an empty dictionary in a tuple differently than an empty dictionary in other collections when it comes to matching Iterable[Dict[..., ...]]
.
Expected Behavior
With the given file:
from typing import Iterable, Dict, Any
def f(x: Iterable[Dict[str, str]]) -> None:
pass
# Lists all work as expected
f([])
f([{}])
f([{"k": "v"}])
# Empty tuple works
f(())
# Tuple of empty dict doesn't work
f(({},))
# Tuple with non-empty dict works
f(({"k": "v"},))
and running mypy
with --strict
you should receive no errors because Tuple[Dict[empty]]
should match Iterable[Dict[str, str]]
.
Actual Behavior
$ mypy --strict testme.py
testme.py:17: error: Argument 1 to "f" has incompatible type "Tuple[Dict[<nothing>, <nothing>]]"; expected "Iterable[Dict[str, str]]"
Found 1 error in 1 file (checked 1 source file)
which is erroring out on this line:
f(({},))
Your Environment
- Mypy version used: 0.910
- Mypy command-line flags:
--strict
- Python version used: 3.8.6
- Operating system and version: Ubuntu 20.04
This is potentially related to #6613 where an empty collection isn't matching a collection type?