Skip to content

Combination of collections where element types are compatible only works left-to-right #5948

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

Closed
PeterJCLaw opened this issue Nov 24, 2018 · 2 comments
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-type-variables

Comments

@PeterJCLaw
Copy link
Contributor

Currently mypy supports combining a list of integers to a list of floats:

y = [float('inf')] + list(range(10))

and the resulting type is builtins.list[builtins.float*].

It would be great if this worked with the collections in the reverse order:

x = list(range(10)) + [float('inf')]

Currently the latter errors with List item 0 has incompatible type "float"; expected "int".

I'm not sure whether this is a limitation of general support for combining generic collections, or there's something special for extending lists of floats by lists of integers.

Either way, it might also be good if this was a general thing for all collections of compatible generics.

Currently I'm using a cast so that my code checks ok, though I'd like to be able to remove that.

@ilevkivskyi
Copy link
Member

We actually already have a fix for this, see #5873, but it triggers another issues.

@JukkaL will you have time to look if there is a simple solution fo this?

@ilevkivskyi ilevkivskyi added bug mypy got something wrong topic-type-variables priority-1-normal false-positive mypy gave an error on correct code labels Nov 24, 2018
@PeterJCLaw
Copy link
Contributor Author

Aha, thanks. I missed that. I'm happy to consider this a duplicate of #5492.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-type-variables
Projects
None yet
Development

No branches or pull requests

2 participants