You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mypy infers that the type of [*enumerate(["x", "y"])] is List[str], when it should be List[Tuple[int, str]].
A repro is below, with a slightly simplified copy of the typeshed definition of enumerate. Note that type inference is right if I define enumerate() as a function instead of a class.
$ python -m mypy tmp/enumunpack.py
tmp/enumunpack.py:14: note: Revealed type is 'builtins.list[builtins.str*]'
tmp/enumunpack.py:21: note: Revealed type is 'builtins.list[Tuple[builtins.int, builtins.str*]]'
$ cat tmp/enumunpack.py
from typing import Iterable, Iterator, Tuple, TypeVar, Generic
_T = TypeVar("_T")
class enumerate(Iterable[Tuple[int, _T]], Generic[_T]):
def __init__(self, iterable: Iterable[_T], start: int = ...) -> None:
...
def __iter__(self) -> Iterator[Tuple[int, _T]]:
...
reveal_type([*enumerate(["x", "y"])])
def enumerate_fn(iterable: Iterable[_T]) -> Iterator[Tuple[int, _T]]:
...
reveal_type([*enumerate_fn(["x", "y"])])
I tried this on master and on 0.730.
The text was updated successfully, but these errors were encountered:
This seems to happen only in certain contexts. I wonder if we are missing a map_instance_to_supertype call somewhere. In particular, for x, y in enumerate(...) seems to work.
Mypy infers that the type of
[*enumerate(["x", "y"])]
isList[str]
, when it should beList[Tuple[int, str]]
.A repro is below, with a slightly simplified copy of the typeshed definition of enumerate. Note that type inference is right if I define
enumerate()
as a function instead of a class.I tried this on master and on 0.730.
The text was updated successfully, but these errors were encountered: