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

Infer type of empty collection from sibling #5871

Closed
lincolnq opened this issue Nov 6, 2018 · 3 comments
Closed

Infer type of empty collection from sibling #5871

lincolnq opened this issue Nov 6, 2018 · 3 comments

Comments

@lincolnq
Copy link
Contributor

lincolnq commented Nov 6, 2018

The following example makes it clear:

my_dict = {
    'a': [1,2],
    'b': []
}
reveal_type(my_dict)  # error: Revealed type is 'builtins.dict[builtins.str*, builtins.object*]'

I expected my_dict to have type Dict[str, List[int]] rather than Dict[str, object].

Possibly related to #1055.

@ilevkivskyi
Copy link
Member

This may be not as easy as it looks, mypy's inference is already exponentially complex, see #3796 so we need to be careful not to slow it down even more. Potentially we can special case built-in collections and their "literals".

@JukkaL
Copy link
Collaborator

JukkaL commented Nov 8, 2018

This looks basically the same as #230. Can we close this as a duplicate?

@ilevkivskyi
Copy link
Member

Oh, yes, this is a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants