Closed
Description
This is fine:
from typing import Iterator
def foo() -> Iterator[int]:
yield 42
x = next(foo()) + 1000
print(x)
But now try this:
from typing import Iterator
def foo() -> Iterator[int]:
yield 42
return 'abc'
This complains about the return
statement:
g.py, line 5: Incompatible return value type: expected typing.Iterator[builtins.int], got builtins.str
It's matching the generator return value (which is only accessible by a caller that uses yield from
) to the declared return type (which is just the type of what you get by calling foo()
.