Closed
Description
This is similar to #14811, but still reproduces on master
following bed49ab:
from typing import TypeVar
T = TypeVar("T")
class Foo:
count: int
def __init__(self) -> None:
self.count = 0
def __iter__(self: T) -> T:
return self
def __next__(self) -> int:
self.count += 1
if self.count > 3:
raise StopIteration
return self.count
a, b, c = Foo()
reveal_type(a) # note: Revealed type is "Any"
Mypy should have enough information here to infer that the type of a
is int
.
Mypy versions tested on
- mypy 1.2.0+dev.bed49ab3781f28be2a6cf5c6665934a8fa2bb5f2 (compiled: no)
- Also reproducible on mypy playground on mypy 1.0.0: https://mypy-play.net/?mypy=latest&python=3.11&gist=fcc3254474f3eda979e0412589379404