-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Wrong type inference (object instead of List) #6968
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
Comments
There is a policy that mypy never infers o: List[Sized] = [[1, 2], ["foo", "bar"]] |
Thanks for your investigation, I don't have any legitimacy to discuss your policies, from an external eye it seems too bad to prefer the inference of
I will try your suggestion to use explicit type annotation :) |
The workaround gets a little tedious when your problematic list is being defined as part of a dictionary. You still have to explicitly assert its type after the fact: assert isinstance(foo["o"], list) |
This is a won't fix. mypy's inference should never produce |
Bug: the following code (Python 3.6.7, mypy 0.701)
Outputs a type of
builtins.list[builtins.object*]
instead of something likebuiltins.list[builtins.list[Any]]
. This in turn makes mypy raise an error (in my case) when I try to apply alen
operation on elements of that list:Outputs:
error: Argument 1 to "len" has incompatible type "object"; expected "Sized"
This is probably related to #4975 but only the union of
Tuple
was evoked there, and it seems that there is the same problem on lists.Thanks!
The text was updated successfully, but these errors were encountered: