Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
RiseT opened this issue Nov 12, 2020 · 1 comment
Closed

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

RiseT opened this issue Nov 12, 2020 · 1 comment
Labels
reason: inexpressable Closed, because this can't be expressed within the current type system stubs: false positive Type checkers report false errors

Comments

@RiseT
Copy link

RiseT commented Nov 12, 2020

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

@RiseT RiseT changed the title Missing type definition for dict(List[List[str]] Missing type definition for dict(List[List[str]]) Nov 12, 2020
@srittau srittau added the stubs: false positive Type checkers report false errors label Nov 12, 2020
@srittau
Copy link
Collaborator

srittau commented Nov 12, 2020

This came up before in #2862, where we concluded not to change anything in typeshed for now. python/typing#592 discusses a general solution for this problem. The example is easily fixed by using tuples, but this is of course not possible in more complex cases.

@srittau srittau closed this as completed Nov 12, 2020
@srittau srittau added the reason: inexpressable Closed, because this can't be expressed within the current type system label Nov 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reason: inexpressable Closed, because this can't be expressed within the current type system stubs: false positive Type checkers report false errors
Projects
None yet
Development

No branches or pull requests

2 participants