我正在尝试为一个生成器函数编写一个 :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
。正确的暗示是什么?