Skip to content

Unexpected error when creating a Dict from a list of lists len 2 #6542

Closed
@adamtheturtle

Description

@adamtheturtle

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions