:rtype:
ジェネレータ関数の型ヒントを記述しようとしています。返される型は何ですか?
たとえば、文字列を生成する次の関数があるとします。
def read_text_file(fn):
"""
Yields the lines of the text file one by one.
:param fn: Path of text file to read.
:type fn: str
:rtype: ???????????????? <======================= what goes here?
"""
with open(fn, 'rt') as text_file:
for line in text_file:
yield line
戻り値の型は単なる文字列ではなく、文字列の反復可能なものなのでしょうか? と書くだけではだめです:rtype: str
。正しいヒントは何でしょうか?
ベストアンサー1
Generator[str, None, None]
またはIterator[str]