Skip to content

Wrong type inference (object instead of List) #6968

Closed as not planned
Closed as not planned
@cdesvernois

Description

@cdesvernois

Bug: the following code (Python 3.6.7, mypy 0.701)

o = [[1, 2], ["foo", "bar"]]
reveal_type(o)

Outputs a type of builtins.list[builtins.object*] instead of something like builtins.list[builtins.list[Any]]. This in turn makes mypy raise an error (in my case) when I try to apply a len operation on elements of that list:

[len(x) for x in o]

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!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions