Closed
Description
I have the following code which works.
from typing import Dict
my_list = ['a', 'b']
my_dict: Dict[str, str] = dict([my_list])
print(my_dict) # {'a': 'b'}
mypy
gives the following error:
example.py:4: error: List item 0 has incompatible type "List[str]"; expected "Tuple[str, str]"
I expect that in this case mypy
would not show an error because the code is valid.
From https://docs.python.org/3/library/stdtypes.html#dict:
Each item in the iterable must itself be an iterable with exactly two objects.
From python/mypy#6542 (comment) (@srittau):
Seems like a typeshed issue. Possibly
dict.__init__()
is missing an overload like:@overload def __init__(self, iterable: Iterable[Iterable[Union[_KT, _VT]]], **kwargs: _VT) -> None: ...