What is the return type hint of a generator function? [duplicate]
Generator
Generator[str, None, None]
or Iterator[str]
The generic type for annotating generators is Generator[yield_type, send_type, return_type]
provided by the typing
module:
def echo_round() -> Generator[int, float, str]:
res = yield
while res:
res = yield round(res)
return 'OK'
Alternatively you can use Iterable[YieldType]
or Iterator[YieldType]
.