Skip to content

Invalid type inferred for list indexing with Any #5250

Closed
@JukkaL

Description

@JukkaL

The revealed type for the following program is List[Any], while the correct type would be Any -- looks like the wrong overload item is picked:

from typing import Any, List

i: Any
a: List[Any]
reveal_type(a[i])  # List[Any], but should be Any

Here is a self-contained repro:

from typing import Any, overload, TypeVar, Generic

T = TypeVar('T')

class A(Generic[T]):
    @overload
    def f(self, x: int) -> T: ...
    @overload
    def f(self, x: slice) -> A[T]: ...
    def f(self, x): ...

i: Any
a: A[Any]
reveal_type(a.f(i))  # A[Any], but should be Any

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions