Skip to content

Missing type definition for dict(List[List[str]]) #4762

@RiseT

Description

@RiseT

The following code example, specifically the instantiation of a dictionary containing list of lists, gets marked as illegal by Pylance, which seems to be due a missing type definition in the typshed repo:

employee_titles = [
    ["Mary", "Senior Manager"],
    ["Brian", "Vice President"],
    ["Julie", "Assistant Vice President"],
]

a = dict(employee_titles) # this line gets flagged as invalid by Pylance
print(a)

Error message from Pylance:

No overloads for "dict(employee_titles)" match parameters
Argument types: (List[List[str]]) Pylance (reportGeneralTypeIssues)

The code above runs without any complaints from Python itself. Also, the Python docs state that the positional argument must be an iterable object, and lists are iterable objects:

Otherwise, the positional argument must be an iterable object. Each item in the iterable must itself be an iterable with exactly two objects. The first object of each item becomes a key in the new dictionary, and the second object the corresponding value.

Reference to Pylance issue: microsoft/pylance-release#594

Metadata

Metadata

Assignees

No one assigned

    Labels

    reason: inexpressibleClosed, because this can't be expressed within the current type systemstubs: false positiveType checkers report false errors

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions