我正在尝试为生成器函数编写 :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
。正确的提示是什么?
最佳答案
Generator[str, None, None]
或 Iterator[str]
关于python - 生成器函数的返回类型提示是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43658999/