ジェネレータ関数の型ヒント
collections.abc.Generator
IMO:typing.Generatorの代わりに型ヒントに使いたい考え
Pythonのジェネレータ関数の返り値の型ヒントを考える
collections.abc.Iteratorやcollections.abc.Iterableでも型ヒントできる
返り値(ReturnType)の型だけでアノテーション(ref: typing.Generator)
#mypy のドキュメント(トップの例)にもある
code:example.py
def fib(n: int) -> Iteratorint:
a, b = 0, 1
while a < n:
yield a
a, b = b, a+b