Today I had this bug, and mypy didn't catch it:
from collections.abc import Iterator
def get_strings(foo: bool) -> Iterator[str]:
if foo:
return ["foo1", "foo2"]
else:
yield "bar1"
yield "bar2"
print(list(get_strings(True))) # empty list
IMO this should be a type checking error. It might be fixable in typeshed by adjusting how/when Generator becomes a subtype of Iterator. If it isn't, I suggest just closing this issue, because there's already so many mypy issues that this would surely be a duplicate.